How do I pick a random number on multiple ranges

Get help using Construct 2

Post » Sat Aug 22, 2015 11:00 pm

I want to create an object at a random X location that is random on two ranges.

Like on the interval: [a, b] AND [c, d]

I might want to create an object that is outside the layer on either side.
B
6
S
1
Posts: 33
Reputation: 495

Post » Sat Aug 22, 2015 11:21 pm

choose(int(random(A,B+1)), int(random(C,D+1)))
ImageImageImage
B
71
S
22
G
267
Posts: 3,807
Reputation: 147,745

Post » Sat Aug 22, 2015 11:25 pm

Thanks. Is there a way I can give weights to the arguments to choose()?

Like say I wanted it to generate a number on [10, 20] 1/3 of the time and [70,85] 2/3 of the time?
B
6
S
1
Posts: 33
Reputation: 495

Post » Sat Aug 22, 2015 11:28 pm

I mean I know for that specific example I could do like choose(random(10, 20), random(70, 85), random(70, 85))

But what if the weights weren't integers or large integers with no large common factors, so I'd have to spam the random()'s in many times?
B
6
S
1
Posts: 33
Reputation: 495

Post » Sat Aug 22, 2015 11:31 pm

I found a way:

Can't post url's yet but the thread was titled "Weighted probabilities"
B
6
S
1
Posts: 33
Reputation: 495


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 25 guests