# How do I pick a random number on multiple ranges

Get help using Construct 2

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

### » Sat Aug 22, 2015 11:21 pm

choose(int(random(A,B+1)), int(random(C,D+1)))
B
72
S
22
G
288
Posts: 3,862
Reputation: 158,460

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

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

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