MathGroup Archive 2002

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

Search the Archive

Re: simulating random variables

  • To: mathgroup at
  • Subject: [mg32856] Re: [mg32831] simulating random variables
  • From: Tomas Garza <tgarza01 at>
  • Date: Fri, 15 Feb 2002 02:50:04 -0500 (EST)
  • References: <>
  • Sender: owner-wri-mathgroup at

A look at the graph of the CDF of the binomial distribution with such a huge
n suggests that it is quite close to the normal distribution (and to the
Poisson, too, of course). You may of course use sampling from the Poisson
(or the normal) as a faster equivalent. Producing normal random numbers is
extremely fast, as you point out, and I would have no qualms about using
them as a good approximation in this case.  I suggest you use RandomArray to
produce your samples, since it is much faster than using Table:

Timing[Table[Random[NormalDistribution[1000, Sqrt[990.]]],
    {10000}]; ]
{0.38 Second, Null}

Timing[RandomArray[NormalDistribution[1000, Sqrt[990.]],
    10000]; ]
{0.06 Second, Null}

A sample of size 10,000 is obtained about 6 times faster! BTW, a few years
ago I proposed a method for sampling from discrete distributions which
appears to be quite efficient. You may take a look at the section "Tricks of
the Trade", in p. 440 (Poisson Distribution), The Mathematica Journal, Vol.
7, Issue 4, 2000.

Tomas Garza
Mexico City

----- Original Message -----
From: "Aaron E. Hirsh" <aehirsh at>
To: mathgroup at
Subject: [mg32856] [mg32831] simulating random variables

> 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

  • Prev by Date: Re: Nonatomic expression ? in Append command
  • Next by Date: Re: simulating random variables
  • Previous by thread: simulating random variables
  • Next by thread: Re: simulating random variables