# Random Two Numbers?

### » Sun Sep 18, 2011 5:55 am

I don't mean like random(50), I random two values. Like 1 and 5. Each tick the value would be 1 or 5. Not in between.
B
11
S
3
G
8
Posts: 473
Reputation: 4,569

### » Sun Sep 18, 2011 6:14 am

Try this -

random(2) * 4 + 1

Random(2) gives you either 0 or 1.

Granted, this only works for the given example. A fancier method would use the conditional operator as such -

(random(2) = 0 ? numA : numB)

This acts like an if statement. numA is returned if the condition -- random(2) = 0 -- is true, and numB returns if false.linkman20042011-09-18 06:18:10
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

### » Sun Sep 18, 2011 10:03 pm

Another method not mentioned is using an array expression:
{1, 5} at (random(2)+1)

Some other examples:
{"spring", "summer", "fall", "winter"} at (random(4)+1)
{1, 1, 2, 3, 5, 7, 12} at (random(7)+1)
B
79
S
24
G
54
Posts: 4,749
Reputation: 40,761

### » Mon Sep 19, 2011 1:56 am

Thanks for the idea rojo, I should use array expressions more often.
B
134
S
65
G
16
Posts: 1,766
Reputation: 19,190

### » Mon Sep 19, 2011 5:45 am

Thanks guys.
B
11
S
3
G
8
Posts: 473
Reputation: 4,569