Most programming languages have a built-in random number generator. Using an a priori random seed can be useful in testing simulations using randomness. In simulations with non-linear growth, small differences at the beginning of the simulations can result in significantly different time evolution of the outputs. To help test such simulations as compared against known-good reference data, it can be useful to set a known random seed to see that expected outputs result.
In Python Numpy, the random seed can be set:
r = numpy.random.default_rng(seed=0)
x = r.standard_normal(3)
Observe that “x” will always be
[ 0.12573022 -0.13210486 0.64042265]
using different seed values result in a different set of repeatable pseudorandom numbers.
NOTE: the default RNG is not guaranteed to be stable over Numpy releases. The user may wish to specify a specific RNG like:
r = numpy.random.Generator(numpy.random.PCG64(seed=0))