Full name
random.getrandbits
Library
random
Syntax
random.getrandbits(k)
Description
The random.getrandbits function returns a positive integer of k random bits drawn from a uniform distribution.
Parameters
- k: Number of random bits of the number to generate.
Result
The random.getrandbits function returns a positive integer.
Examples
We can generate a random 4-bit number with the following code:
random.getrandbits(4)
7