Parallelization and evaluation of random number generation - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-22T04:58:16Z https://mathematica.stackexchange.com/feeds/question/60329 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/60329 2 Parallelization and evaluation of random number generation user19944 https://mathematica.stackexchange.com/users/19944 2014-09-21T22:44:04Z 2014-09-22T07:05:27Z <p>Suppose I have the following functions:</p> <pre><code>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]] </code></pre> <ol> <li>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)?</li> <li>Relating to the first question, once parallelized is there a more efficient way of writing or executing this resulting code?</li> </ol> https://mathematica.stackexchange.com/questions/60329/-/60350#60350 1 Answer by molekyla777 for Parallelization and evaluation of random number generation molekyla777 https://mathematica.stackexchange.com/users/11981 2014-09-22T07:05:27Z 2014-09-22T07:05:27Z <p>All function you need it's <code>DistributeDefinitions</code> and <code>ParallelTry</code></p> <pre><code>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]] </code></pre>