Hi, How can I add a number with the generated number which consists of 18 digits?
a = 100 + random.random(18) I want to get the result 100151215121512161518
Hi, How can I add a number with the generated number which consists of 18 digits?
a = 100 + random.random(18) I want to get the result 100151215121512161518
from random import randint a = int("100" + str(randint(1e18, 1e19-1))) print(a) a = int(100e19) + randint(1e18, 1e19-1) print(a) random.random(18) in the question, but now it doesn't work for you? - Nick Volynkin ♦ >>> from random import randrange >>> 10**20 + randrange(10**18) 100202623310201395011 randrange not randrange return too small a number? - Qwertiy ♦10**20 to 10**20+10**18-1 . Given that the author uses (broken) random.random(18) , the interpretation that '0'*18 contains 18 zeros (digits) is quite appropriate and the final formula in the answer is more logical. - jfs a = '100' + str(random.randint(1e18, 1e19-1)) It turns out to be a string . If you need a number , add int
a = int('100' + str(random.randint(1e18, 1e19-1))) For example, like this: a = int(str(100) + str(random.randint(100000000000000000, 999999999999999999)))
random.random(18) with random.randint(100000000000000000, 999999999999999999) - ragmon >>> a = int(str(100)+"".join([str(random.randint(1,9)) for i in range(18)])) >>> a 100613877729784556545 a = int(str(100)+"".join([str(random.randint(0,9)) for i in range(18)])) - Alexander LoevSource: https://ru.stackoverflow.com/questions/615398/
All Articles