On this page
random.seed
Prev: random.sample | Up: random | Next: random.setstate
Rel: random.betavariate, random.binomialvariate, random.choice, random.choices
Ref: docs.python.org — random.seed
Tags: #public #python3 #stdlib #random
Import
import random
from random import seed
Signature & Overview
random.seed(a=None, version=2)
Initialize internal state from a seed.
Usage
import random
rng = random.Random()
rng.seed(99)
a = rng.random()
rng.seed(99)
assert rng.random() == a
Gotchas
- Avoid mutating the global generator with
random.seed()in libraries: Create a localrandom.Random(seed)instance instead.
REPL Inspect
from random import seed
help(seed)
Linked from
Related notes
- tuts/python3/stdlib_module/random/sample Linked here; links to this page; shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/setstate 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