# Random Two Numbers?

For questions about using Classic.

### » 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
115
S
41
G
20
Posts: 1,586
Reputation: 19,196

### » 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
100
S
38
G
134
Posts: 5,556
Reputation: 85,325

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

Thanks for the idea rojo, I should use array expressions more often.
B
168
S
81
G
22
Posts: 1,815
Reputation: 24,857

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

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

Return to Help & Support using Construct Classic

### Who is online

Users browsing this forum: No registered users and 2 guests