How to generate a string of bits using Python?

PythonProgramming

You can generate random bit strings of given size using the random module's getrandbits function that accepts a number of bits as an argument. 

example

import random
hash = random.getrandbits(128)
print(hex(hash))

Output

This will give the output −

0xa3fa6d97f4807e145b37451fc344e58c
raja
Published on 20-Apr-2018 07:23:49
Advertisements