Observe:
TableForm@
Map[{First[Timing[RandomVariate[BinomialDistribution[10 #, 1/#]]]],
First[Timing[RandomVariate[BinomialDistribution[10 #, 1/(# + 1)]]]]} &,
{1500, 3000, 5000, 10000}]
0. 0.733205
0. 1.809612
0. 3.447622
0. 0.
Note how the timing goes through the roof simply lowering the probability a tiny amount.
If appears for lowish n in Binomial[n,p]
, when n*p<10, things get strange.
9.01 Windows, would appreciate if others could confirm behavior.
N.b - the times above are on my loungebook, so you might need to use this on a real machine to compare - do you see the same drop?:
TableForm@
Map[{First[Timing[Do[RandomVariate[BinomialDistribution[10 #, 1/#]], {100}]]],
First[Timing[Do[RandomVariate[BinomialDistribution[10 #, 1/(# + 1)]], {100}]]]} &,
{1500, 3000, 5000, 10000}]
Update: This appears to be caused by heuristics in method switching (hazily outlined in the documentation), probably between a lookup/alias and other methods. This can be seen from:
Table[{MaxMemoryUsed[RandomVariate[BinomialDistribution[10 x, 1/(x)]]],
MaxMemoryUsed[RandomVariate[BinomialDistribution[10 x, 1/(x + 1)]]]},
{x, {9999, 10000}}]
(* {{3320, 12630024}, {3200, 2440}} *)
Where in this case, x>=10K uses an alternate method.
{0.015625, 0.03125}, {0.`, 0.0625}, {0.`, 0.125}, {0.`, 0.`}}
Windows 8.1, Mathematica 10.0.0.0 $\endgroup${0.03, 0.1, 0.17, 0.0001}
for the second column $\endgroup$AbsoluteTiming[]
was used instead? $\endgroup$