# Are there rules of thumb for knowing when RandomVariate is more efficient than RandomReal?

From a fresh Mathematica kernel, RandomVariate is more efficient for NormalDistribution but RandomReal is for uniformly distributed noise.

RandomReal[NormalDistribution[0, 1], 100]; // Timing

{0.00535, Null}

RandomVariate[NormalDistribution[0, 1], 100]; // Timing

{0.000069, Null}

RandomReal[{0, 1}, 100]; // Timing

{0.00004, Null}

RandomVariate[UniformDistribution[], 100]; // Timing

{0.005236, Null}

But if I re-evaluate, I get Timing results that are much more similar:

RandomReal[NormalDistribution[0, 1], 100]; // Timing

{0.000051, Null}

RandomVariate[NormalDistribution[0, 1], 100]; // Timing

{0.000052, Null}

RandomReal[{0, 1}, 100]; // Timing

{0.00003, Null}

RandomVariate[UniformDistribution[], 100]; // Timing

{0.000058, Null}

Does caching the distribution definition really matter that much?

Obviously RandomVariate has the advantage that it can generate data from mixed (not only fully continuous or fully discrete) distributions. So it is more general. But if one is generating random numbers from standard distributions like the normal or the Poisson, is there any advantage – performance or otherwise – to using RandomVariate instead of RandomReal or RandomInteger?

-
I didn't even know that RandomReal worked for distributions – Rojo Mar 4 '12 at 3:55
@Rojo It doesn't seem to be in the main documentation for RandomReal in v8, but can be verified to work with Histogram@RandomReal[NormalDistribution[0, 1], 1000]. It is the way to do it in version 7, and I hadn't adapted to RandomVariate yet. – Verbeia Mar 4 '12 at 4:02
Interesting question – Rojo Mar 4 '12 at 5:26