SeedRandom[s]
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.
SeedRandom
SeedRandom[s]
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.
Examples
open all close allBasic Examples (1)
Use SeedRandom to make random numbers repeatable:
SeedRandom[1234];RandomReal[]SeedRandom[1234];RandomReal[]Scope (3)
SeedRandom["password"];RandomReal[]Reseed the current random number generator:
rgs = SeedRandom[]Create a sequence of 5 random reals:
RandomReal[1, 5]Reseed using the RandomGeneratorState object returned by SeedRandom:
SeedRandom[rgs]The sequence of random real numbers is reproduced:
RandomReal[1, 5]SeedRandom affects all random generators:
SeedRandom[4567];{RandomInteger[10], RandomReal[]}SeedRandom[4567];{RandomReal[], RandomInteger[10]}Options (2)
Method (2)
Switch to the Mersenne twister generator:
SeedRandom[Method -> "MersenneTwister"]Random numbers are now generated using it:
RandomReal[1, 5]A specific seed will affect the current Mersenne twister generator:
SeedRandom[4321];RandomReal[1, 5]Give a seed to all initialized generators:
SeedRandom["Seed all generators", Method -> All]Applications (2)
Reproduce a part of a computation that uses randomness:
SeedRandom[1234]; Eigenvalues[RandomReal[1, {100, 100}], 1]SeedRandom[1234]; Eigenvalues[RandomReal[1, {100, 100}], -1]SeedRandom[1234];Eigenvalues[RandomReal[1, {100, 100}]][[{1, -1}]]Write a function that uses randomness, but returns predictable results:
Options[rplot] = {PlotPoints -> 100, RandomSeed -> 1234};rplot[f_, {x_, xmin_, xmax_}, OptionsPattern[]] := Module[{n = OptionValue[PlotPoints], s = OptionValue[RandomSeed]},
BlockRandom[SeedRandom[s];
ListPlot[Table[{x, f}, {x, RandomReal[{xmin, xmax}, n]}]]]]p100 = rplot[Sin[x], {x, 0, 10π}]Using the function again with more points just adds the additional points:
rplot[Sin[x], {x, 0, 10π}, PlotPoints -> 125]Properties & Relations (4)
SeedRandom returns a RandomGeneratorState object with the new state:
SeedRandom[]When a RandomGeneratorState object is used as a seed, explicit Method options are ignored:
SeedRandom[RandomGeneratorState[{"ExtendedCA", {80, 4, 0}},
{{RawArray["UnsignedInteger64", {2137, 17811601035166618301, 1074886304135541815,
10839886105759978540, 5680751118638851723, 3721304837657701207, 12648882479676994813,
76919680177341524 ... 30824604546838294, 15592153151670727127, 324171737895129758,
11862034057572822428, 6654485145575527276, 5854470426309544231, 11331002485321865147,
7991838028202245200}], 4, 0}}, RawArray["UnsignedInteger64", {10048184177401884856, 0}]], Method -> "Rule30CA"]The state prior to seeding can be obtained from $RandomGeneratorState:
state = $RandomGeneratorStateRandomReal[1, 5]Generate a new seed and and use the new state:
SeedRandom[];RandomReal[1, 5]Seeding with the saved state reproduces the original sequence:
SeedRandom[state];RandomReal[1, 5]BlockRandom effectively saves the random generator state and restores it at the end of the computation:
{SeedRandom[123];RandomReal[], SeedRandom[123];RandomReal[]}{SeedRandom[123];BlockRandom[RandomReal[]], RandomReal[]}Tech Notes
Related Guides
History
Introduced in 1988 (1.0) | Updated in 2007 (6.0) ▪ 2010 (8.0) ▪ 2020 (12.2)
Text
Wolfram Research (1988), SeedRandom, Wolfram Language function, https://reference.wolfram.com/language/ref/SeedRandom.html (updated 2020).
CMS
Wolfram Language. 1988. "SeedRandom." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/SeedRandom.html.
APA
Wolfram Language. (1988). SeedRandom. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SeedRandom.html
BibTeX
@misc{reference.wolfram_2026_seedrandom, author="Wolfram Research", title="{SeedRandom}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/SeedRandom.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_seedrandom, organization={Wolfram Research}, title={SeedRandom}, year={2020}, url={https://reference.wolfram.com/language/ref/SeedRandom.html}, note=[Accessed: 12-June-2026]}