urandom
– Random Number Generation¶
The module ‘’urandom’’ provides functions for random number generation. ‘’urandom’’ is based upon the random
module in the Python standard library.
Functions¶
-
urandom.
getrandbits
(n)¶ Returns an integer with
n
random bits where n may be between 1-32 (inclusive).
-
urandom.
seed
(n)¶ Initialize the random number generator with a known integer
n
. This will give you reproducibly deterministic randomness from a given starting state (n
).
-
urandom.
randint
(a, b)¶ Return a random integer
N
such thata <= N <= b
. Alias forrandrange(a, b+1)
.
-
urandom.
randrange
(start[, stop[, step]])¶ randrage(stop) returns a randomly selected integer between zero and up to (but not including)
stop
.randrange(start, stop) return a randomly selected integer from
range(start, stop)
.randrange(start, stop, step) returns a randomly selected element from
range(start, stop, step)
.
-
urandom.
choice
(seq)¶ Return a random element from the non-empty sequence
seq
. Ifseq
is empty, raisesIndexError
.
-
urandom.
random
()¶ Return the next random floating point number in the range [0.0, 1.0)
-
urandom.
uniform
(a, b)¶ Return a random floating point number
N
such thata <= N <= b
fora <= b
andb <= N <= a
forb < a
.