简体   繁体   中英

generate a random number with fixed length

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM