simulating random variables

• To: mathgroup at smc.vnet.net
• Subject: [mg32831] simulating random variables
• From: "Aaron E. Hirsh" <aehirsh at stanford.edu>
• Date: Thu, 14 Feb 2002 01:44:02 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```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

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: Understanding the Output
• Next by Date: Re: Stumped again on a simple list
• Previous by thread: Re: Notebook manipulation
• Next by thread: Re: simulating random variables