How can I generate a big (more than 64 bits) random integer in Python?
Random integers can be generated using functions such as randrange() and randint(). Let us first take a look at randint(). In case you want to generate numbers in intervals, you can use the randrange() function.
print(randint(1, 100)) # Pick a random number between 1 and 100. x = randint(1, 100) # Pick a random number between 1 and 100.
Generating Random Integersrandom. randint() function returns a random integer between a and b (in this case, 1 and 500) which includes a and b, in other words: a<= x <=b. Whereas random. randrange() chooses a random item from that range (start=0, stop=500, step=5), which can be 0, 5, 10, 15 and so on, until 500.
You can use random.getrandbits()
:
>>> random.getrandbits(128) 117169677822943856980673695456521126221L
As stated in the linked documentation, random.randrange()
will also do the trick if random.getrandbits()
is available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With