|
-
Dec 8th, 2000, 03:00 PM
#1
Thread Starter
New Member
When I start my program I want to create random numbers but when I enter the code it will always display the random numbers in the same order, when I exit and re-open the program. How do I make it so that everytime I relaunch the program it generates random numbers in a completely different order?
Thanks,
Will
-
Dec 8th, 2000, 03:46 PM
#2
Fanatic Member
Are you using the Rnd function?? If so you need to make a call to the Randomize function before hand to assure that you don't always get the same values....
Code:
Dim iCt as Integer
dim iArray(1 to 5) as Integer
For iCt = 1 to 5
Randomize
iArray(iCt) = rnd * 20
Next iCt
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Dec 8th, 2000, 03:53 PM
#3
New Member
I would prolly put the randomize function at the start of your code, you should only need to call it once to "seed" the random number generator.
Gazz
-
Dec 8th, 2000, 04:10 PM
#4
Fanatic Member
I don't know the difference between
And
Some people use Randomize Timer, I don't know why.
-
Dec 8th, 2000, 05:12 PM
#5
Fanatic Member
Good point gazz here is the corrected code..
Code:
Dim iCt as Integer
dim iArray(1 to 5) as Integer
Randomize
For iCt = 1 to 5
iArray(iCt) = rnd * 20
Next iCt
Also there is no point in saying Randomize Timer because according to VB Help file if you omit the seed parameter the Timer is automatically used to generate the random seed
From the visual basic reference
Randomize Statement
Initializes the random-number generator.
Syntax
Randomize [number]
The optional number argument is a Variant or any valid numeric expression.
Remarks
Randomize uses number to initialize the Rnd function's random-number generator, giving it a new seed value. If you omit number, the value returned by the system timer is used as the new seed value.
If Randomize is not used, the Rnd function (with no arguments) uses the same number as a seed the first time it is called, and thereafter uses the last generated number as a seed value.
Note To repeat sequences of random numbers, call Rnd with a negative argument immediately before using Randomize with a numeric argument. Using Randomize with the same value for number does not repeat the previous sequence.
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Dec 15th, 2000, 02:41 PM
#6
Thread Starter
New Member
Thanks
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
|