RandomGeneratorState
✖
RandomGeneratorState
Details

- 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
Examples
open allclose allBasic Examples (2)Summary of the most common use cases
Get the current state of the pseudorandom generator:

https://wolfram.com/xid/0c0qyxxy4y0ew-4lc5su

Use a RandomGeneratorState object to seed BlockRandom:

https://wolfram.com/xid/0c0qyxxy4y0ew-0tmjou

Scope (5)Survey of the scope of standard use cases
Seed the current random generator and save the resulting state:

https://wolfram.com/xid/0c0qyxxy4y0ew-go82tg

A particular sequence of numbers is generated:

https://wolfram.com/xid/0c0qyxxy4y0ew-2bws09

Reseed using the RandomGeneratorState object:

https://wolfram.com/xid/0c0qyxxy4y0ew-kkkun7

The same sequence of numbers is generated:

https://wolfram.com/xid/0c0qyxxy4y0ew-n2avm2

Some methods have states that can only be restored in the same session:

https://wolfram.com/xid/0c0qyxxy4y0ew-fe2446

SeedRandom will work as expected in the same kernel session:

https://wolfram.com/xid/0c0qyxxy4y0ew-vo8omr

Trying to restore these states in a new kernel session will restore the method but not the state:

https://wolfram.com/xid/0c0qyxxy4y0ew-8nwe25


Some methods do not have a restorable state:

https://wolfram.com/xid/0c0qyxxy4y0ew-m0g8vd


https://wolfram.com/xid/0c0qyxxy4y0ew-mwzsyu

SeedRandom can use these to set the method, but random sequences will not be reproduced:

https://wolfram.com/xid/0c0qyxxy4y0ew-6xp8ub


https://wolfram.com/xid/0c0qyxxy4y0ew-04qdc7

Programmatically extract the method name:

https://wolfram.com/xid/0c0qyxxy4y0ew-r8h6el

Programmatically determine whether the state survives the end of the kernel session:

https://wolfram.com/xid/0c0qyxxy4y0ew-ktg1wd


https://wolfram.com/xid/0c0qyxxy4y0ew-evhqb7

Applications (1)Sample problems that can be solved with this function
Create a version of BlockRandom that refuses to run if the current random state cannot be restored:

https://wolfram.com/xid/0c0qyxxy4y0ew-ungfyk
Activate a randomness generation method with no restorable state:

https://wolfram.com/xid/0c0qyxxy4y0ew-gng5us

Because this method cannot be seeded, BlockRandom cannot give reproducible results:

https://wolfram.com/xid/0c0qyxxy4y0ew-z04pbl


The function will refuse to evaluate:

https://wolfram.com/xid/0c0qyxxy4y0ew-p2a999

Activate a randomness generation method that possesses a restorable state:

https://wolfram.com/xid/0c0qyxxy4y0ew-mzke01

The function restores the random state at the end of each evaluation:

https://wolfram.com/xid/0c0qyxxy4y0ew-50vfvy

Hence the following result matches the previous result:

https://wolfram.com/xid/0c0qyxxy4y0ew-x1k940

Properties & Relations (5)Properties of the function, and connections to other functions
When available, the state hash is returned as an integer:

https://wolfram.com/xid/0c0qyxxy4y0ew-hl0h3d

If the state hash has expired, it is returned as None:

https://wolfram.com/xid/0c0qyxxy4y0ew-h4nfwh

The current random generator state is stored in $RandomGeneratorState:

https://wolfram.com/xid/0c0qyxxy4y0ew-6j8vip

SeedRandom returns a RandomGeneratorState object:

https://wolfram.com/xid/0c0qyxxy4y0ew-ve8qh4


https://wolfram.com/xid/0c0qyxxy4y0ew-lp4orc

A RandomGeneratorState object can be used as a seed in SeedRandom and related functions:

https://wolfram.com/xid/0c0qyxxy4y0ew-h4677p
Use state in SeedRandom:

https://wolfram.com/xid/0c0qyxxy4y0ew-kb70xs

Use it to seed computations in BlockRandom:

https://wolfram.com/xid/0c0qyxxy4y0ew-u20hxx

Possible Issues (1)Common pitfalls and unexpected behavior
When a session-only RandomGeneratorState object is given to SeedRandom, a copy is created:

https://wolfram.com/xid/0c0qyxxy4y0ew-xpinqs

This copy has a different session hash:

https://wolfram.com/xid/0c0qyxxy4y0ew-fpo05e

However, both RandomGeneratorState objects produce the same random sequences:

https://wolfram.com/xid/0c0qyxxy4y0ew-zre1vm

Wolfram Research (2020), RandomGeneratorState, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomGeneratorState.html.
Text
Wolfram Research (2020), RandomGeneratorState, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomGeneratorState.html.
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.
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
Wolfram Language. (2020). RandomGeneratorState. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomGeneratorState.html
BibTeX
@misc{reference.wolfram_2025_randomgeneratorstate, author="Wolfram Research", title="{RandomGeneratorState}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/RandomGeneratorState.html}", note=[Accessed: 06-April-2025
]}
BibLaTeX
@online{reference.wolfram_2025_randomgeneratorstate, organization={Wolfram Research}, title={RandomGeneratorState}, year={2020}, url={https://reference.wolfram.com/language/ref/RandomGeneratorState.html}, note=[Accessed: 06-April-2025
]}