Random string of digits?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Dec 25 08:48:16 EST 2011


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)


-- 
Steven



More information about the Python-list mailing list