Internal states..

Chad Netzer cnetzer at sonic.net
Wed Sep 10 01:54:59 CEST 2003


On Tue, 2003-09-09 at 15:00, ryan10975073 at netscape.net wrote:

>  What i would like to know is what the word 'internal states' means with context to seed value??

When you set the seed, you are setting the "internal state" of the
random number generator.  So every time you set the seed to, for
example, 42, you will start to produce the exact same sequence of random
numbers.  The "internal state" is just all the information needed for
this to happen.  For simple RNGs it may be a single integer, or perhaps
two or three integers.

What the manual is saying is that even though you can supply (for
example), a 32 bit seed, only 24 bits of state data is really kept
internally.  Ie. the 32 bits get mapped down to 2**24 real, distinct
starting seeds.  I'm not sure why, in this case, but probably due to
compatibility with older (possibly 8-bit CPU?) versions.  The internal
state itself may be more than 24 bits, but you still have at most 2**24
distinct sequences of random values (they all start looping at some
point).

This has implications if you (for example) are doing statistical tests
on the seed values to see how distinct the generated sequences are.  Or
if you assign "seeds" thinking they all produce distinct sequences of
values; they don't.

The topic of random number generation is an interesting and surprisingly
complicated one.  There are much better and more advanced RNG that are
now "state of the art", such as the Mersenne Twister (part of
Python2.3), and "cryptographic random number generation" which is WAY
beyond what whrand provides.

PS. pedants, please correct any misinformation; I'm winging this one.

-- 
Chad Netzer






More information about the Python-list mailing list