Random string of digits?

Joshua Landau joshua.landau.ws at gmail.com
Sun Dec 25 12:45:09 EST 2011


On 25 December 2011 17:32, Serhiy Storchaka <storchaka at gmail.com> wrote:

> 25.12.11 15:48, Steven D'Aprano написав(ла):
>
>  On Sun, 25 Dec 2011 08:30:46 -0500, Roy Smith wrote:
>>
>>> I want to create a string of 20 random digits (I'm OK with leading
>>> zeros).  The best I came up with is:
>>> ''.join(str(random.randint(0, 9)) for i in range(20))
>>> Is there something better?
>>>
>> '%20d' % random.randint(0, 10**20-1)
>>
>
> '%020d' % random.randrange(10**20)


Do the docs not advise .format now?

"{:20}".format(random.randrange(10**20))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111225/fba1e83a/attachment-0001.html>


More information about the Python-list mailing list