resets the pseudorandom generator, using s as a seed.
resets the generator, using as a seed the time of day and certain attributes of the current Wolfram System session.
Details and Options
- You can use SeedRandom[s] to make sure you get the same sequence of pseudorandom numbers on different occasions.
- SeedRandom affects RandomInteger, RandomReal, RandomComplex, RandomPrime, RandomChoice, RandomSample, and RandomVariate.
- Possible settings for the seed s include:
RandomGeneratorState[…] a RandomGeneratorState object n an integer "seed" a string Automatic automatically choose whether to reseed based on options
- SeedRandom returns a RandomGeneratorState that for deterministic generators can be used as a seed in order to reproduce random sequences.
- SeedRandom[Method->"method"] specifies what method should be used for the pseudorandom generator. If "method" has been previously used, this form does not reseed it.
- SeedRandom[n,Method->"method"] resets the generator, specifying both a seed and the method to use.
- SeedRandom[n] affects only the current generator; SeedRandom[n,Method->All] affects all generators for which seeds have been given.
- Typical possible methods include:
"Congruential" linear congruential generator (low-quality randomness) "ExtendedCA" extended cellular automaton generator (default) "OpenSSL" OpenSSL cryptographically secure generator "MersenneTwister" Mersenne twister shift register generator "MKL" Intel MKL generator (Intel-based systems) "Rule30CA" Wolfram Rule 30 generator
- Different methods may give sequences with different levels of randomness.
Examplesopen allclose all
Basic Examples (1)
Use SeedRandom to make random numbers repeatable:
Reseed the current random number generator:
Create a sequence of 5 random reals:
Reseed using the RandomGeneratorState object returned by SeedRandom:
The sequence of random real numbers is reproduced:
SeedRandom affects all random generators:
Properties & Relations (4)
SeedRandom returns a RandomGeneratorState object with the new state:
When a RandomGeneratorState object is used as a seed, explicit Method options are ignored:
The state prior to seeding can be obtained from $RandomGeneratorState:
Generate a new seed and and use the new state:
Seeding with the saved state reproduces the original sequence:
BlockRandom effectively saves the random generator state and restores it at the end of the computation:
Wolfram Research (1988), SeedRandom, Wolfram Language function, https://reference.wolfram.com/language/ref/SeedRandom.html (updated 2020).
Wolfram Language. 1988. "SeedRandom." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/SeedRandom.html.
Wolfram Language. (1988). SeedRandom. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SeedRandom.html