Re: Random Normal deviates within compiled function?

• To: mathgroup at smc.vnet.net
• Subject: [mg62302] Re: Random Normal deviates within compiled function?
• From: John Doty <jpd at whispertel.LoseTheH.net>
• Date: Sat, 19 Nov 2005 23:18:29 -0500 (EST)
• References: <dln17e\$gf4\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Gareth Russell wrote:

> Hi All,
>
> I have a function which needs to be quick as it's used in simulations,
> and it requires the internal generation of a large vector of random
> normal deviates (up to 50,000). It appears that a function like
> Random[NormalDistribution[0,s]] cannot be compiled. Can anyone suggest
> an algorithm for getting such numbers that would work within a Compile
> statement and still be quicker than using the non-compiled function?
>
> The non-compiled function would look as follows:
>
> f[v_,r_,k_,s_,q_]:=Select[v*Exp[r*(1 - v/k) +
>        RandomArray[NormalDistribution[0, s],
>           Length[v]]], # > q &]
>
> where v is a vector of 50,000 reals, and r, k, s and q are scalar reals.
>
> (If anyone is interested, this is for population projection in
> population viability analysis.)
>
> Thanks,
>
> Gareth Russell
> NJIT
>

I've been using the following:

fastNoise = Compile[{}, 2.(Random[] + Random[] + Random[] - 1.5)];

It makes variates with mean 0, variance 1, with a roughly normal