getrandbits(k) -> x. Generates an int with k random bits.
(self, k)
| 900 | return (int.from_bytes(_urandom(7)) >> 3) * RECIP_BPF |
| 901 | |
| 902 | def getrandbits(self, k): |
| 903 | """getrandbits(k) -> x. Generates an int with k random bits.""" |
| 904 | if k < 0: |
| 905 | raise ValueError('number of bits must be non-negative') |
| 906 | numbytes = (k + 7) // 8 # bits / 8 and rounded up |
| 907 | x = int.from_bytes(_urandom(numbytes)) |
| 908 | return x >> (numbytes * 8 - k) # trim excess bits |
| 909 | |
| 910 | def randbytes(self, n): |
| 911 | """Generate n random bytes.""" |
no outgoing calls
no test coverage detected