|
-
Sep 19th, 2002, 10:40 AM
#1
Thread Starter
Frenzied Member
Can this be optimize
Hello, i did a script that shuffle number from 0 to 7,
just need to know if it can be optimize
VB Code:
Randomize
Dim rndArr(), tmp, isOk, x
x = 0
ReDim rndArr(x)
Do Until x = 8
tmp = CInt(Rnd() * 7)
isOk = True
For y = 0 To x - 1
If rndArr(y) = tmp Then
isOk = False
Exit For
End If
Next
If isOk = True Then
rndArr(x) = tmp
x = x + 1
ReDim Preserve rndArr(x)
End If
Loop
-
Sep 19th, 2002, 12:56 PM
#2
Frenzied Member
Yes!
Type cast all of your variables. isOk is boolean; rndArr(), tmp, x and y are integers. Numeric variants use 16 bytes of memory, integers and booleans use 2. Then there is the overhead required to manipulate them.
Since you know rndArr will have 8 elements, Dim it as such and stop ReDimming. ReDim also has a lot of overhead.
-
Sep 19th, 2002, 01:00 PM
#3
you cant type cast in vbscript ccoder. eveything is a variant in vbscript.
-
Sep 19th, 2002, 01:01 PM
#4
Thread Starter
Frenzied Member
2 thing, first of all it's asp, so there's no
Dim x As Integer
your right about the 2nd thing, it's because at first
i was looping thru the rndArr, but i change my code and
now it would be ok!!so here's the changes
VB Code:
Randomize
Dim rndArr(7), tmp, isOk, x
x = 0
Do Until x = 8
tmp = CInt(Rnd() * 7)
isOk = True
For y = 0 To x - 1
If rndArr(y) = tmp Then
isOk = False
Exit For
End If
Next
If isOk Then
rndArr(x) = tmp
x = x + 1
End If
Loop
-
Sep 19th, 2002, 01:31 PM
#5
Frenzied Member
Originally posted by Cander
you cant type cast in vbscript ccoder. eveything is a variant in vbscript.
D'oh! I see that now Guess I read the post too fast.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|