evaluates expr with all pseudorandom generators localized, so that uses of SeedRandom, RandomInteger, and related functions within the evaluation of expr do not affect subsequent pseudorandom sequences.

Details and Options

  • BlockRandom[expr] in effect saves the states of all pseudorandom generators before evaluating expr, then restores them afterwards.
  • BlockRandom[expr] always gives the same result as just evaluating expr, though it can affect values obtained for subsequent expressions.
  • BlockRandom[expr,RandomSeeding->seeding] specifies that the random generators should be seeded with the specified seeding before evaluating expr.
  • BlockRandom has attribute HoldFirst.
  • Many built-in functions in the Wolfram Language effectively use BlockRandom.


open allclose all

Basic Examples  (2)

Use BlockRandom to localize the use of a pseudorandom generator:

Use BlockRandom to prevent one use of a randomized algorithm from affecting others:

Scope  (1)

BlockRandom works with all pseudorandom generators in the Wolfram Language:

Options  (3)

RandomSeeding  (3)

Use a particular random seed to ensure predictable results:

When a generator is used outside BlockRandom, the results without seeding are changed:

Use a RandomGeneratorState object to simultaneously specify the seed and method:

Use Automatic seeding to get different results every time:

Applications  (2)

Run a randomized algorithm without affecting other random sequences:

Compute a Monte Carlo approximation to :

BlockRandom prevents other random sequences from being affected:

Get the "same" random number at different precisions:

Properties & Relations  (1)

BlockRandom effectively does the same as resetting the random seed to its previous value:

Wolfram Research (2007), BlockRandom, Wolfram Language function, (updated 2017).


Wolfram Research (2007), BlockRandom, Wolfram Language function, (updated 2017).


@misc{reference.wolfram_2021_blockrandom, author="Wolfram Research", title="{BlockRandom}", year="2017", howpublished="\url{}", note=[Accessed: 25-June-2021 ]}


@online{reference.wolfram_2021_blockrandom, organization={Wolfram Research}, title={BlockRandom}, year={2017}, url={}, note=[Accessed: 25-June-2021 ]}


Wolfram Language. 2007. "BlockRandom." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2017.


Wolfram Language. (2007). BlockRandom. Wolfram Language & System Documentation Center. Retrieved from