Repeating Random Numbers
Posted: Wed Mar 19, 2008 6:31 pm
I need help with Basic's pseudo-random numbers. I'm trying to generate a sequence of random numbers from a seed.
For example, if InitSeed = 745, I would like to be able to generate the same sequence of number every cycle of the loop.
InitSeed% = 745
FOR i% = 1 TO 3
FOR j% = 1 TO 5
RANDOMIZE InitSeed%
Num% = INT(100 * (RND + 1))
PRINT Num%
NEXT j%
NEXT i%
If the sequence were 55, 75, 33, 83, 18..... I would like the output to be this sequence printed 3 times using the InitSeed.
I've only been able to get the desired output IF I run one loop, re-start the program, and run it again. But if it's part of a running program, RANDOMIZING the InitSeed has no effect.
For example, if InitSeed = 745, I would like to be able to generate the same sequence of number every cycle of the loop.
InitSeed% = 745
FOR i% = 1 TO 3
FOR j% = 1 TO 5
RANDOMIZE InitSeed%
Num% = INT(100 * (RND + 1))
PRINT Num%
NEXT j%
NEXT i%
If the sequence were 55, 75, 33, 83, 18..... I would like the output to be this sequence printed 3 times using the InitSeed.
I've only been able to get the desired output IF I run one loop, re-start the program, and run it again. But if it's part of a running program, RANDOMIZING the InitSeed has no effect.