SHA-based subclass for random module
Trevor Perrin
trevp_spam at trevp.net
Mon Mar 22 21:27:08 EST 2004
Paul Rubin wrote:
> trevp at trevp.net (Trevor Perrin) writes:
>
>>
>>What about a subclass of Random that provides an interface to
>>platform-specific secure RNGs:
[...]
>
> I think it's extremely desirable and important to add such an
> interface, and maybe it should go in the random module, but it
> shouldn't be a subclass of Random. Random is intended to be a
> deterministic generator.
I see that seed(), getstate() and setstate() imply determinism.
Aside from those, the nice thing about subclassing Random is you'd only
have to implement random() and getrandbits() and you'd get randrange(),
randint(), choice(), shuffle(), and sample() for free. So it might be
worth it, even if you have to raise NotImplementedError for a few methods.
Actually, Random could be made even easier to subclass. getrandbits
(which is new in 2.4) returns a long. It would be better for us if
there was a getrandstring() function that an underlying generator could
implement. This would also be a helpful addition to the API, at least
for cryptographic uses.
Trevor
http://www.python.org/dev/doc/devel/lib/module-random.html
More information about the Python-list
mailing list