|
-
Feb 22nd, 2000, 08:35 PM
#1
Thread Starter
New Member
Do you have any idea to reduce the time on generate a large ammount(e.g > 10000) of random number into array?
My code is :
dim temp as long
dim arr() as long
dim maxvalue as long
redim arr(1 to x)
For temp=1 to x
arr(temp) = int(rnd*maxvalue)+1
next temp
.
.
.
is it possible to speed up the program??
-
Feb 22nd, 2000, 09:06 PM
#2
Assuming that you need a random number and are storing in an array for future referencing:
You could make a private function that generates the number, then the first time you need that number save it to the array for future use.
This will appearingly cut your time making the processing as close to parallel as possible.
Example:
Loop
'Process
'I need a random number
Get_Rand
'save number to array
'continue processing
end loop
Function Get_Rand()
'Generate random nummber
End
-
Feb 22nd, 2000, 09:54 PM
#3
Member
[QUOTE][B]
Oneway is to reduce the amount of variables in your loop. Instead of x use 100000 and maxvalue use a number.
If you want a random number less than 36000 then define ARR as an integer.
It is faster for VB to store integers than long numbers
Edited by Sacred_knight on 02-23-2000 at 11:18 AM
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
|