Internal states..

Chad Netzer cnetzer at sonic.net
Tue Sep 9 22:39:03 EDT 2003


On Tue, 2003-09-09 at 19:05, ryan10975073 at netscape.net wrote:
> Chad Netzer <cnetzer at sonic.net> wrote:

>   Thank you. Sounds interesting. :~) well do you know any resource or something i can dwell into
>  for "Mersenne Twister (part of Python2.3),and "cryptographic random number generation" ??

For Mersenne Twister, just search on Google.  Same for cryptographic
random number generator (or cryptographic hash).  Mind you, the latter
are HEFTY subjects, with lots of math.  The crypto RNG topics require a
lot of knowledge about cryptography in general, to understand fully.

>  And what u are saying is that everytime the seed([x]) where x = long int, it would return the same value??

Yes.

$ python2.3
Python 2.3 (#1, Aug 12 2003, 13:06:21)
>>> import random
>>> help(random)
 
>>> random.seed(0)
>>> random.random()
0.84442185152504812
>>> random.random()
0.75795440294030247
>>> random.random()
0.420571580830845

>>> random.seed(0)
>>> random.random()
0.84442185152504812
>>> random.random()
0.75795440294030247
>>> random.random()
0.420571580830845


>  if it does thats then whats the point ??

Setting the seed has several uses.  You can store its value to repeat
sequences of events (sometime used in simulations).  You can create
truely random seed values somehow, then use them to set the seed (the
system time values are typically a small subset of all possible seeds,
and similar starting seeds can produce simlar values on poorly made
RNGs)

>  Its better to use seed() which is based on the system's time then..

If you don't care about the specific seed, yes, just let the system make
one for you.  For cryptographic applications (which the RNGs we are
talking about are NOT suited for, generally), it is very bad advice to
use the system time, alone, as a seed.

> And i think we can't use Mersenne Twister RNG in Python if i am not wrong.

Python2.3 comes with it.  It is just an implementation detail (but it is
generally considered a better, faster RNG than the previous
implementation).  It is what I used above.

Is there any reason you didn't send your reply to the Python mailing
list?  I'm CC'ing the list, since there is nothing personal in this
email, and it started on the list.


-- 
Chad Netzer






More information about the Python-list mailing list