3
$\begingroup$

I have spent a half hour searching Mathematica.SE for information on this topic, with no luck. The code is:

RandomChoice[
  {40, 30, 1} -> 
    {BlockRandom[RandomChoice[{0, 0}], RandomSeeding -> Automatic],
     BlockRandom[RandomChoice[{1, 5}], RandomSeeding -> Automatic], 
     BlockRandom[RandomChoice[{6, 10}], RandomSeeding -> Automatic]}, 
   20]

A typical output is:

{0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 5, 0, 5, 0, 5, 0}

Why does the code give only the same two numbers repeatedly? isn't RandomSeeding supposed to prevent this type of output?

$\endgroup$
  • 6
    $\begingroup$ Use RuleDelayed instead of Rule, e.g., RandomChoice[{40, 30, 1} :> {..}]. $\endgroup$ – Carl Woll May 18 '18 at 1:13
  • $\begingroup$ That works great, thanks! $\endgroup$ – Michael B. Heaney May 18 '18 at 1:34
  • $\begingroup$ It looks like using RuleDelayed also obviates using BlockRandom and RandomSeeding! $\endgroup$ – Michael B. Heaney May 18 '18 at 1:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.