# Tag Info

8

The key to speedup here is generating the set of random number in one go instead of calling RandomVariate repeatedly. Generally, instead of Table[RandomVariate[...], {size}] use RandomVariate[..., size] It can also generate a multidimensional array of random values in one go. I rewrote your code to do this: out = AbsoluteTiming[Table[ ...

3

So, in the first place, if you're concerned about performance, you probably don't want to be looping like that and incrementing a counter. It's not going to be as fast as you'd like it to be. Unparallelized, this... AbsoluteTiming[c = 0; Do[If[RandomReal[] > 0.5, c += 1], {i, 100000}]; c] (* {0.111647, 49853} *) ...is about half as fast as this: ...

2

Try this: ClearAll[discretePlot]; SetAttributes[discretePlot,HoldAll]; discretePlot[args___]:= Block[{SystemDiscretePlotDumpflatTable}, SetAttributes[SystemDiscretePlotDumpflatTable,HoldFirst]; SystemDiscretePlotDumpflatTable[expr_,eval_,{var_},{vals_}]:= ParallelTable[expr,{var,vals}]; ...

1

Yes, they run independently, as they are independent processes. But Mathematica takes the random seed from the system time, so if you start several independent processes at the same time, they will likely all generate the same sequence of random numbers. (When I tried this they did.) It sounds like you should use Mathematica's parallel tools instead, ...

Only top voted, non community-wiki answers of a minimum length are eligible