Random Two Numbers?

For questions about using Classic.

Post » 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

Post » 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
113
S
41
G
20
Posts: 1,586
Reputation: 19,126

Post » 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
94
S
33
G
114
Posts: 5,357
Reputation: 73,775

Post » Mon Sep 19, 2011 1:56 am

Thanks for the idea rojo, I should use array expressions more often.
B
151
S
75
G
20
Posts: 1,793
Reputation: 22,749

Post » 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 3 guests