random.getrandbits() in Python
random module is used to generate random numbers in Python. Not actually random, rather this is used to generate pseudo-random numbers. That implies that these randomly generated numbers can be determined.
getrandbits() method of the
random module is used to return an integer with a specified number of bits. The number of bits required in the result is passed as an parameter in the method.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
Input : getrandbits(4) Output : 14 (the binary equivalent of 14 is 1110 which has 4 bits) Input : getrandbits(16) Output : 60431 (the binary equivalent of 14 is 1110110000001111 which has 16 bits)
10 0 1 14