Random string of digits?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Dec 25 10:27:37 EST 2011


On Mon, 26 Dec 2011 01:51:30 +1100, Chris Angelico wrote:

> On Mon, Dec 26, 2011 at 1:21 AM, Roy Smith <roy at panix.com> wrote:
>> It turns out, I don't really need 20 digits.  If I can count on
>>
>>>>> "%020d" % random.randint(0,999999999999999)
>>
>> to give me 15-ish digits, that's good enough for my needs and I'll
>> probably go with that.  Thanks.
> 
> I'd say you can. The information about the Mersenne Twister underlying
> the module's functions isn't marked as "CPython Implementation Note", so
> I would expect that every Python implementation will provide a minimum
> of 53-bit precision. (It does have the feeling of an implementation
> detail though; is there a guarantee that two Pythons will generate the
> same sequence of numbers from the same seed?)

Yes.

http://docs.python.org/dev/library/random.html#notes-on-reproducibility

I think that's a new guarantee. Previously, the answer was only yes-ish: 
in theory, no guarantee was made, but in practice, you could normally 
rely on it. For example, when the Mersenne Twister became the default 
random number generator, the old generator, Wichman-Hill, was moved into 
its own module whrandom (deprecated in 2.4; now gone) for those who 
needed backwards compatibility.


-- 
Steven



More information about the Python-list mailing list