# Random Values Range

Get help using Construct 2

### » Fri Oct 26, 2012 11:46 am

Hey all, been trying to solve a problem involving random values, and have had a good search through the manual and forums but can't seem to figure this out...

I'm trying to pick a random value between 1 and 3, and are currently using this which works fine (the 'Ceil' rounds the numbers up to whole decimals, which is what i want):

Ceil(Random(3))

But how do I use this to pick only 1 or 3 (i need to exclude 2). I thought it would be something like this, but it doesn't work:

Ceil(Random(1,3))

Thinking it would choose either 1 or 3...I think I'm barking up the wrong tree with this logic.

Does anyone know a way to do this? Totally appreciate the help...FatRat2012-10-26 12:13:42
B
16
S
5
G
2
Posts: 20
Reputation: 2,227

### » Fri Oct 26, 2012 1:37 pm

You're basically just choosing between two numbers so just do random(2) check if it's over 1 and return 3 else return 1.

random(2) > 1 ? 3 : 1
Find all the Construct 2 games that were on Steam Greenlight here
B
42
S
11
G
7
Posts: 513
Reputation: 7,355

### » Fri Oct 26, 2012 1:55 pm

Like this: CapX

I would have used arrays and for loops but I'm not sure how to convert:

var array = [1,3];

for(var i = 0; i < 1; i++)
{
//Just a text function to output the text, use whatever you want
console.log(array);
}

to the construct 2 equivalent. lonehangman2012-10-26 13:59:29
B
19
S
9
G
6
Posts: 77
Reputation: 5,356

### » Fri Oct 26, 2012 5:28 pm

You could use the choose(1,3) function.
B
101
S
39
G
134
Posts: 5,588
Reputation: 85,514

### » Fri Nov 16, 2012 9:55 am

Thanks for the replies (and sorry for the late reply myself, I tried to reply last week but was getting an error on the forums).

I used OddConfections suggestion of this "random(2) > 1 ? 3 : 1" which did exactly what I needed in the end.

The 'choose(1,3) option sounds useful though. I didn't know about that function.FatRat2012-11-16 09:56:18
B
16
S
5
G
2
Posts: 20
Reputation: 2,227