Re: Simulation

• To: mathgroup at smc.vnet.net
• Subject: [mg19411] Re: [mg19353] Simulation
• From: "Mark E. Harder" <harderm at ucs.orst.edu>
• Date: Mon, 23 Aug 1999 13:57:20 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```Roberto,
First, replace the Random[Integer,...] function with a user-defined
function ranStep, which returns -1 and 1 1/6 of the time and 0 the remainder
of the times (Press, et.al. "Numerical Recipes in Fortran" describe this
method of converting a uniform random distribution to one with unequal
probabilities):

ranStep[]:=If[
Random[Real,{0.,1.}]<N[1/6],Return[-1],
If[Random[Real,{0.,1.}]>N[5/6],Return[1],Return[0] ] ]

Then use it in the statement you already wrote:

data=Table[NestList[#+0.01*ranStep[]&,5,100]]

Out[113]=
{5,5,4.99,4.99,4.99,4.99,4.99,4.99,4.99,4.99,4.99,4.99,4.99,4.99,4.99,5.,5.,

4.99,4.98,4.98,4.98,4.98,4.98,4.98,4.98,4.98,4.98,4.97,4.97,4.97,4.97,4.97,

4.98,4.98,4.97,4.97,4.96,4.96,4.96,4.96,4.96,4.96,4.97,4.97,4.96,4.95,4.95,

4.95,4.95,4.95,4.95,4.95,4.96,4.96,4.96,4.95,4.95,4.95,4.94,4.94,4.94,4.94,

4.93,4.93,4.93,4.93,4.93,4.93,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.95,

4.96,4.97,4.97,4.98,4.98,4.98,4.98,4.99,4.99,4.99,4.99,4.99,4.98,4.97,4.98,
4.97,4.97,4.96,4.96,4.97,4.96,4.96,4.95,4.95}

-mark

-----Original Message-----
From: Roberto Diego <r-diego at develnet.es>
To: mathgroup at smc.vnet.net
Subject: [mg19411] [mg19353] Simulation

>Hi there,
>
>I need help on how the expression:
>
>data=Table[NestList[#+0.01*Random[Integer,{-1,1}]&,5,1000]];
>
>could be modified in order to get -1 with probability 1/6, 0 with p 4/6 and
>1 with p 1/6 instead of 1/3,1/3,1/3
>
>Thanks a lot
>
>Roberto Diego