Re: easy question about random numbers

• To: mathgroup at smc.vnet.net
• Subject: [mg53388] Re: [mg53382] easy question about random numbers
• From: DrBob <drbob at bigfoot.com>
• Date: Sun, 9 Jan 2005 23:03:38 -0500 (EST)
• References: <200501090402.XAA12446@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Here's a post that explains a very fast method:

http://forums.wolfram.com/mathgroup/archive/2004/Sep/msg00105.html

There are other methods in the thread, too.

Bobby

On Sat, 8 Jan 2005 23:02:44 -0500 (EST), Pedrito <pedrito6 at softhome.net> wrote:

> Hi everybody!
>
> I wanted to obtain a discrete random number generator that I needed for
> a project.
>
> On the library Statistics`DiscreteDistributions` I could find the DiscreteUniformDistribution
> function. But I wanted to specify the probability for each one of the
> states.
>
>
> For instance:
> If we need to simulate an unfair dice, we could have this probabilities
> for each one of the sides:
> {1/6, 1/6, 1/6, 1/6, 9/60, 11/60}
>
> So I wrote:
> li2 = {1/6, 1/6, 1/6, 1/6, 9/60, 11/60}
> li3=FoldList[Plus,0,li2]
> Module[{i = 1, r = Random[]}, While[ !li3[[i]] < r < li3[[i + 1]], i++]; i]
>
> It works ok but I don't know if there is another (better) way of doing
> this.
> Any suggestion?
>
>
>
>

--
DrBob at bigfoot.com
www.eclecticdreams.net

```

• Prev by Date: Re: easy question about random numbers
• Next by Date: Strange installation problem