Using SHA1 as RNG

Irmen de Jong irmen at
Fri Mar 14 20:09:22 CET 2003

Klaus Alexander Seistrup wrote:
> 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.  So I
> thought, why not use SHA1 in the core generator?  Perhaps something
> along these lines:

> It is probably quite expensive to use the sha module for shuffling
> the bits, but the resulting period is huge.

How would you know?
For that matter,
	self._hash = self._sha.digest()
may produce exactly the same hash as before, endlessly.

> What do you guys think?  Is it worth it?  I meant to use it for
> generating uuids, but perhaps it's overkill?

I think your idea is flawed, sorry. It only depends on a few random
values at seeding time, and after that - see my previous comment.

Even if the hash doesn't repeat itself, you still get a 100%
predictible sequence of numbers because the SHA algorithm is repeatable.


More information about the Python-list mailing list