Random choice between two numbers

Get help using Construct 2

Post » Sat Jan 28, 2012 12:51 am

I need to get a random number that is -20 OR 500, not a range, I need it every tick.

I already tried with the | operator but I don't think it works this way

Thanks
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Sat Jan 28, 2012 1:00 am

There is an OR plug in you could look into. :)

Or perhaps you could force the range to result in 500 with a little math.

I could also see a variable driven solution,

random, if result > than X, variable = -20

random, if result < than X, variable = 500
Khaz2012-01-28 01:04:45
B
11
S
3
G
2
Posts: 110
Reputation: 2,410

Post » Sat Jan 28, 2012 1:14 am

[QUOTE=0plus1] I need to get a random number that is -20 OR 500, not a range
Thanks[/QUOTE] -20+floor(random(0,2))*500
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Sat Jan 28, 2012 1:17 am

[QUOTE=ranma] [QUOTE=0plus1] I need to get a random number that is -20 OR 500, not a range
Thanks[/QUOTE] -20+floor(random(2))*500
[/QUOTE]
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Sat Jan 28, 2012 1:21 am

I see that the tough laws of mathematics always rule over our world, never though about doing it like this!

Wouldn't your example yield -20 or 480 though?
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Sat Jan 28, 2012 1:46 am

It would :) I believe you now know what to do to make it work for you though. Cheers
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Sat Jan 28, 2012 11:29 am

If someone who doesn't know how this works.

-20+floor(random(2))*520 (this is the right formula in my case)

a general would be

You need number X or number Y

X+floor(random(2))*(Y-X)

p.s. Thank you very much ranma0plus12012-01-28 11:29:43
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Sat Jan 28, 2012 1:59 pm

i just noticed the system expression:

choose(Value, Value)

so in your case the supersimple answer is use it! :)

choose(-20,500)

have fun!ranma2012-01-28 13:59:55
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Sat Jan 28, 2012 5:22 pm

Good to now! Thanks Again!
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Sun Jan 29, 2012 1:20 am

Yeah, I just noticed this thread and was going to mention choose(). Incredibly useful function, that one.
B
126
S
7
G
4
Posts: 185
Reputation: 7,233

Next

Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], h1k3, Unconnected and 0 guests