gives a representation of the internal state of a pseudorandom generator.
- RandomGeneratorState[…] contains the generator method, method parameters and, when applicable, the full internal state.
- A RandomGeneratorState object can be given to SeedRandom to restore the state it represents.
- Some methods have a state that can only persist for the duration of the kernel session in which it was created.
- The following properties can be extracted using RandomGeneratorState[…]["prop"]:
"CrossSessionPersistent" whether the internal state persists past the current kernel session "Method" method name "StateHash" the hash of the state as an integer
Examplesopen allclose all
Basic Examples (2)
Reseed using the RandomGeneratorState object:
SeedRandom will work as expected in the same kernel session:
SeedRandom can use these to set the method, but random sequences will not be reproduced:
Create a version of BlockRandom that refuses to run if the current random state cannot be restored:
Because this method cannot be seeded, BlockRandom cannot give reproducible results:
Properties & Relations (5)
If the state hash has expired, it is returned as None:
The current random generator state is stored in $RandomGeneratorState:
Use state in SeedRandom:
Use it to seed computations in BlockRandom:
Wolfram Research (2020), RandomGeneratorState, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomGeneratorState.html.
Wolfram Language. 2020. "RandomGeneratorState." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RandomGeneratorState.html.
Wolfram Language. (2020). RandomGeneratorState. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomGeneratorState.html