|
SOLUTIONS
|
BUILT-IN MATHEMATICA SYMBOL
BlockRandom
BlockRandom[expr]
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.
DetailsDetails
- 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 has attribute HoldAll.
- Many built-in functions in Mathematica effectively use BlockRandom.
ExamplesExamplesopen allclose all
Basic Examples (2)Basic Examples (2)
Use BlockRandom to localize the use of a pseudorandom generator:
| In[1]:= |
| Out[1]= |
Use BlockRandom to prevent one use of a randomized algorithm from affecting others:
| In[1]:= |
| Out[1]= |
| In[2]:= |
| Out[2]= |
New in 6
Mathematica 9 is now available!
New to Mathematica?
Find your learning path »
Have a question?
Ask support »
