MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: simulating random variables

  • To: mathgroup at
  • Subject: [mg32851] Re: [mg32831] simulating random variables
  • From: "Johannes Ludsteck" <johannes.ludsteck at>
  • Date: Fri, 15 Feb 2002 02:49:55 -0500 (EST)
  • Organization: Universitaet Regensburg
  • Sender: owner-wri-mathgroup at

Dear Aaron,
unfortunately I have no simple idea how to speed up
generation of binomial random deviates, but I can
give you two standard references on pseudorandom variable
[1] Luc Devroye (I have forgotten the title)
[2] Johnson: Multivariate Statistical Simulation, 1987.

However, the Mathematica implementation is likely to be efficient. 

As for the normal random variables, if you
need large lists or arrays of r.v., a *simple*
method to speed up things considerably ist to use
RandomArray[]. On my computer, RandomArray is
about 10 times faster for 100000 draws:

Out[1]= {3.62 Second,Null}
Out[2]= {0.33 Second,Null}

I guess that is impossible to speed up RandomArray,
since the implementation is considerably efficient.
Have a look at the Package Statistics`NormalDistribution`
if you don't believe this.

Best regards,

On 14 Feb 2002, at 1:44, Aaron E. Hirsh wrote:

> Dear All,
> I need to simulate a large number of binomial random variables. 
> Unfortunately, when the parameter n (number of trials) is large, the 
> simulation of binomial random variables is relatively time consuming. 
> For example, if I would like to simulate a binomial random variable 
> with parameters n = 10000 and p =0.01:
> In[134]:=
> Timing[Random[BinomialDistribution[100000,0.01]]]
> Out[134]=
> {0.283333 Second,1007}
> One possibility for saving time would be to use an approximation. For 
> small p, an appropriate approximation is the Poisson. While this is 
> definitely better:
> In[135]:=
> Timing[Random[PoissonDistribution[(.01)(100000)]]]
> Out[135]=
> {0.0333333 Second,1002}
> , it is still much slower than using a normal:
> In[136]:=
> \!\(Timing[
>      Random[NormalDistribution[(.01)(100000),((.01)(100000)(.99))^0.5]]]\)
> Out[136]=
> {0. Second,1025.3}
> Does anyone know how I could speed up my simulation of binomial or 
> poisson-distributed random variables? I would also be interested in 
> ways of speeding up the simulation of the Normal, though it seems 
> extraordinarily efficient already.
>      Thank you very much,
> Aaron Hirsh
> -- 
> Aaron E. Hirsh
> Center for Computational Genetics and Biological Modeling
> Stanford University
> tel. (650) 723-4952
> fax. (650) 725-0180

Johannes Ludsteck
Institut fuer Volkswirtschaftslehre
Lehrstuhl Prof. Dr. Moeller
Universitaet Regensburg
Universitaetsstrasse 31
93053 Regensburg
Tel +49/0941/943-2741

  • Prev by Date: Re: simulating random variables
  • Next by Date: Re: Linebreaks and style when saving as TeX
  • Previous by thread: Re: simulating random variables
  • Next by thread: Linebreaks and style when saving as TeX