       Re: Relational Operators and Random Integers

• To: mathgroup at smc.vnet.net
• Subject: [mg90342] Re: [mg90305] Relational Operators and Random Integers
• From: peter <pl.0 at mac.com>
• Date: Sun, 6 Jul 2008 07:20:44 -0400 (EDT)
• References: <200807050849.EAA16731@smc.vnet.net>

```Pete
I think the RandomChoice function is persistent;

In:= x:=RandomChoice[{1,2,3}]
In:= x
Out= 1
In:= x
Out= 2
In:= x
Out= 1
In:= x
Out= 3
In:= x
Out= 1
In:= x
Out= 2

Peter Lindsay

On 5 Jul 2008, at 09:49, Peter Evans wrote:

> Hi all,
>
> I'm a new user of Mathematica 6 and am struggling with some basics.
> I wish to write a set of rules which are dependent upon a random
> variable. I've been using RandomChoice to choose my variable and
> then large If and Which statements to produce my desired dynamics.
>
> The problem is that the number that these statements end up spitting
> out aren't recognised as what they are in further If and Which
> statements. Here's a simple example that demonstrates my problem:
>
> In:= x := RandomChoice[{1, 2, 3}]
> x
> Which[x == 1, 1, x == 2, 2, x == 3, 3]
>
> Out= 1
>
> Out= 2
>
> Mathematica clearly thinks x to be 1 but the If statement indicates
> its 2. What am I doing wrong here?
>
> Much thanks,
>
> Pete
>

```

• Prev by Date: Re: Converting a string to a variable name
• Next by Date: Re: Relational Operators and Random Integers
• Previous by thread: Relational Operators and Random Integers
• Next by thread: Re: Relational Operators and Random Integers