On this page
random.SystemRandom
Prev: random.shuffle | Up: random | Next: random.triangular
Rel: random.betavariate, random.binomialvariate, random.choice, random.choices
Ref: docs.python.org — random.SystemRandom
Tags: #public #python3 #stdlib #random
Import
import random
from random import SystemRandom
Signature & Overview
random.SystemRandom(x=None)
Alternate random number generator using sources provided by the operating system (such as /dev/urandom on Unix or CryptGenRandom on Windows).
Methods & Attributes
SystemRandom.betavariate(self, alpha, beta)— Beta distribution.SystemRandom.binomialvariate(self, n=1, p=0.5)— Binomial random variable.SystemRandom.choice(self, seq)— Choose a random element from a non-empty sequence.SystemRandom.choices(self, population, weights=None, *, cum_weights=None, k=1)— Return a k sized list of population elements chosen with replacement.SystemRandom.expovariate(self, lambd=1.0)— Exponential distribution.SystemRandom.gammavariate(self, alpha, beta)— Gamma distribution. Not the gamma function! Conditions on the parameters are alpha > 0 and beta > 0.SystemRandom.gauss(self, mu=0.0, sigma=1.0)— Gaussian distribution.SystemRandom.getrandbits(self, k)— getrandbits(k) -> x. Generates an int with k random bits.SystemRandom.getstate(self, *args, **kwds)— Method should not be called for a system random number generator.SystemRandom.lognormvariate(self, mu, sigma)— Log normal distribution.SystemRandom.normalvariate(self, mu=0.0, sigma=1.0)— Normal distribution.SystemRandom.paretovariate(self, alpha)— Pareto distribution. alpha is the shape parameter.SystemRandom.randbytes(self, n)— Generate n random bytes.SystemRandom.randint(self, a, b)— Return random integer in range [a, b], including both end points.SystemRandom.random(self)— Get the next random number in the range 0.0 <= X < 1.0.SystemRandom.randrange(self, start, stop=None, step=1)— Choose a random item from range(stop) or range(start, stop[, step]).SystemRandom.sample(self, population, k, *, counts=None)— Chooses k unique random elements from a population sequence.SystemRandom.seed(self, *args, **kwds)— Stub method. Not used for a system random number generator.SystemRandom.setstate(self, *args, **kwds)— Method should not be called for a system random number generator.SystemRandom.shuffle(self, x)— Shuffle list x in place, and return None.SystemRandom.triangular(self, low=0.0, high=1.0, mode=None)— Triangular distribution.SystemRandom.uniform(self, a, b)— Get a random number in the range [a, b) or [a, b] depending on rounding.SystemRandom.vonmisesvariate(self, mu, kappa)— Circular data distribution.SystemRandom.weibullvariate(self, alpha, beta)— Weibull distribution.
Usage
import random
rng = random.SystemRandom()
val = rng.randrange(1, 100)
assert 1 <= val < 100
Gotchas
- Backed by
os.urandom()(CSPRNG): Safe for security-sensitive randomness;.seed(),.getstate(), and.setstate()are no-ops or raiseNotImplementedError.
REPL Inspect
from random import SystemRandom
help(SystemRandom)
Linked from
Related notes
- tuts/python3/stdlib_module/random/shuffle Linked here; links to this page; shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/triangular Linked here; links to this page; shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/betavariate Linked here; shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/binomialvariate Linked here; shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/choice Linked here; shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/choices Linked here; shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/random Linked here; shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/random/expovariate shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/gammavariate shared tags: #random, #stdlib