gives a representation of the internal state of the default pseudorandom generator.
$RandomGeneratorState
gives a representation of the internal state of the default pseudorandom generator.
Details
- $RandomGeneratorState returns a RandomGeneratorState object that can be passed to BlockRandom, SeedRandom and related functions.
Examples
open all close allBasic Examples (1)
Applications (1)
Create a version of BlockRandom that refuses to run if the current random state cannot be restored:
SetAttributes[myBlockRandom, HoldFirst];
myBlockRandom[args__] := If[$RandomGeneratorState["StateHash"] =!= None,
BlockRandom[args],
"Aborting as the active method has no restorable state."]Activate a randomness generation method with no restorable state:
SeedRandom["Method" -> "OpenSSL"]Because this method cannot be seeded, BlockRandom cannot give reproducible results:
SeedRandom[1234, "Method" -> "OpenSSL"]The function will refuse to evaluate:
myBlockRandom[RandomReal[]]Activate a randomness generation method that possesses a restorable state:
SeedRandom["Method" -> "ExtendedCA"]The function restores the random state at the end of each evaluation:
myBlockRandom[RandomReal[]]Hence the following result matches the previous result:
myBlockRandom[RandomReal[]]Properties & Relations (4)
$RandomGeneratorState returns a RandomGeneratorState object:
$RandomGeneratorState//HeadUsing RandomInteger, RandomReal and related functions changes $RandomGeneratorState:
$RandomGeneratorStateUse RandomComplex:
RandomComplex[]The state has changed as indicated by the new hash:
$RandomGeneratorStateThe value of $RandomGeneratorState can be restored with SeedRandom:
state = $RandomGeneratorState;
RandomInteger[100, 10]SeedRandom[state];
RandomInteger[100, 10]Restoring $RandomGeneratorState after a computation is effectively the same as BlockRandom:
Table[Block[{state, result}, state = $RandomGeneratorState;result = RandomInteger[100];SeedRandom[state];result], {5}]Table[BlockRandom[RandomInteger[100]], {5}]Related Guides
History
Text
Wolfram Research (2020), $RandomGeneratorState, Wolfram Language function, https://reference.wolfram.com/language/ref/$RandomGeneratorState.html.
CMS
Wolfram Language. 2020. "$RandomGeneratorState." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/$RandomGeneratorState.html.
APA
Wolfram Language. (2020). $RandomGeneratorState. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/$RandomGeneratorState.html
BibTeX
@misc{reference.wolfram_2026_$randomgeneratorstate, author="Wolfram Research", title="{$RandomGeneratorState}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/$RandomGeneratorState.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_$randomgeneratorstate, organization={Wolfram Research}, title={$RandomGeneratorState}, year={2020}, url={https://reference.wolfram.com/language/ref/$RandomGeneratorState.html}, note=[Accessed: 13-June-2026]}