In Python, how to generate a 12-digit random number? Is there any function where we can specify a range like random.range(12)
?
import random
ran
Since leading zeros are allowed (by your comment), you could also use:
int(''.join(str(random.randint(0,9)) for _ in xrange(12)))
EDIT: Of course, if you want a string, you can just leave out the int
part:
''.join(str(random.randint(0,9)) for _ in xrange(12))
This seems like the most straightforward way to do it in my opinion.