# Parallelization and evaluation of random number generation

Suppose I have the following functions:

f1:=(a=RandomInteger[{1,24}]; b=RandomInteger[{1,24}]; Return[a+b])
f2:=If[f1==2,Print["snake eyes"]; Return[true], Print["nada"]; Return[false]]

1. How can I parallelize these functions so that each kernel continuously executes f1 until any one kernel obtains "snake eyes" (at which point the process should terminate)?
2. Relating to the first question, once parallelized is there a more efficient way of writing or executing this resulting code?
• For a discussion of interkernel communication, the primitives, and the issues that arise, I think this question is quite informative (the question AND the answer, both). Sep 22, 2014 at 0:17

## 1 Answer

All function you need it's DistributeDefinitions and ParallelTry

f1 := RandomInteger[{1, 24}] + RandomInteger[{1, 24}];
func[x_] := While[True,
If[f1 === 2,
Print["snake eyes"];
Return[True]
,(*else*)
Print["nada"]
]
];

ParallelTry[func, Range[\$KernelCount]]