Seeding Random Numbers
Posted: Fri Dec 16, 2005 12:17 pm
Ok, my turn...
There are a couple of topics here dealing with random number/letter generation. My question deals with starting, or seeding Basic's random number genereator (rng).
Generally that is done with the Randomize statement using "timer" as the seed value:
But I have a need to re-seed the rng at a given point in its sequence so that I may reproduce the sequence at a later point in time.
I use: because giving a negative value to the rnd() function as an argument re-starts the sequence at a given point.
Now, back to "Randomize". If you execute that statement with no argument, Q/QuickBASIC will prompt for a seed in the range of -32768 to 32767, the range of two-byte integers. However, you can respond with any 4- or 8- byte real and it appears that it works. However, the sequence is still started randomly.
If I try the same thing with "dummy=rnd(negative value)" it also appears to work AND I re-start at a known point.
Now my question: How many bytes are ACTUALLY used to restart the sequence? Are there really only 65,535 different starting points? Or, since I can use larger values are there more starting points? If I use "timer" I have about 86400 seconds per day times 18.2 timer ticks per second, or about 1.5 million different seed values. In otherwords, how many bytes make up the internal state of BASIC's rng? It's probably more than two, but is it three?, four?, eight? (Not likely.)
I'd be interested to know how many different (potential) sequence seeds I really have. Any bites?
There are a couple of topics here dealing with random number/letter generation. My question deals with starting, or seeding Basic's random number genereator (rng).
Generally that is done with the Randomize statement using "timer" as the seed value:
Code: Select all
RANDOMIZE timer
I use:
Code: Select all
dummy=rnd(-seed)
Now, back to "Randomize". If you execute that statement with no argument, Q/QuickBASIC will prompt for a seed in the range of -32768 to 32767, the range of two-byte integers. However, you can respond with any 4- or 8- byte real and it appears that it works. However, the sequence is still started randomly.
If I try the same thing with "dummy=rnd(negative value)" it also appears to work AND I re-start at a known point.
Now my question: How many bytes are ACTUALLY used to restart the sequence? Are there really only 65,535 different starting points? Or, since I can use larger values are there more starting points? If I use "timer" I have about 86400 seconds per day times 18.2 timer ticks per second, or about 1.5 million different seed values. In otherwords, how many bytes make up the internal state of BASIC's rng? It's probably more than two, but is it three?, four?, eight? (Not likely.)
I'd be interested to know how many different (potential) sequence seeds I really have. Any bites?