Using SHA1 as RNG

Giovanni Bajo noway at
Fri Mar 14 20:51:29 CET 2003

"Klaus Alexander Seistrup" <spam at> ha scritto nel messaggio
news:d2aeb0b6-4701-4a49-be95-c3b9e75efb69 at

> I was looking at python's whrandom and random modules the other day.
> Both seem to have a period of 27814431486575L (30268*30306*30322-1),
> which is, of course, quite a number, but not that long anyway

Python 2.3 will use the Marsenne-Twister RNG, whose period is 2^19937-1. Big
enough I'd say.
It's also faster to calculate.

> So I
> thought, why not use SHA1 in the core generator?  Perhaps something
> along these lines:

Unless you studied the distribution, you have no proof that the resulting
sequence has a long period, for any starting seed. I would not be surprised
if the period was much smaller, in fact. And besides, it would probably be
very slow.

Giovanni Bajo

More information about the Python-list mailing list