random seed

The starting value of a pseudo-random number generator; the same seed always produces the same sequence of numbers.

In more detail

Fixing the seed, for example with random.seed(42) in Python, makes every run produce the same random choices, so bugs are reproducible and test results can be compared. Without a seed, generators usually start from an unpredictable value. Seeded generators are predictable by design, so never use them for security; use a cryptographically secure source such as Python's secrets module instead.

Examples

rng = random.Random(7)
In this course: Seeding makes randomness repeatable, but a test that depends on a seed is coupled to the number and order of every random call in between. Passing in a generator that returns a chosen value is usually a clearer way to test.

Related terms

Taught in

References

Certification courses