0

I want to generate a random number with in two range, and i want it to have fixed length. I don't want to limit the range as offered i How to generate random number with the specific length in python

as following: [10] -> [00010]

[36554] ->[36554]

[554] -> [00554]

Could you guide me please? Thanks

Community
  • 1
  • 1
amin
  • 621
  • 1
  • 8
  • 20

1 Answers1

9
import random
'{0:05}'.format(random.randint(1, 100000))

creates fixed length string representation of a random number like '00554'.

eumiro
  • 207,213
  • 34
  • 299
  • 261