# How do I get a Random number

Get help using Construct 2

### » Wed Oct 15, 2014 7:23 pm

I hope there is someone who can help here
how do I get a random number between 1 and 20, but it may not be able to choose 3 and 15
B
7
S
1
Posts: 8
Reputation: 954

### » Wed Oct 15, 2014 7:32 pm

value = choose(1,2,4,5,6,7,8,9,10,11,12,13,14,16,17,18,19,20)
B
71
S
22
G
274
Posts: 3,826
Reputation: 151,295

### » Wed Oct 15, 2014 7:36 pm

Random(N) - Returns a random number between 0 and N, not including N. The result includes fractions, so random(3) can return 2.5. Use floor(random(n)) to generate a random whole number up to but not including N, e.g. floor(random(3))* will return either 0, 1 or 2. Random(A, B) can also be used to generate a random number between A and B.

And you compare the result and re-roll accordingly.
B
37
S
9
G
3
Posts: 493
Reputation: 4,142

### » Wed Oct 15, 2014 10:10 pm

is it possible to use a variable in the choose function.
B
7
S
1
Posts: 8
Reputation: 954

### » Wed Oct 15, 2014 10:12 pm

blackhornet wrote:value = choose(1,2,4,5,6,7,8,9,10,11,12,13,14,16,17,18,19,20)

is it possible to use a variable in the choose function.
B
7
S
1
Posts: 8
Reputation: 954

### » Wed Oct 15, 2014 11:52 pm

Yes.
B
71
S
22
G
274
Posts: 3,826
Reputation: 151,295

### » Thu Oct 16, 2014 1:30 am

jep77 wrote:
blackhornet wrote:value = choose(1,2,4,5,6,7,8,9,10,11,12,13,14,16,17,18,19,20)

is it possible to use a variable in the choose function.

Would've been quicker just to try that in C2? It's all about experimentation. Try something and see
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

### » Fri Oct 17, 2014 2:44 pm

I think like it:
You do not have the required permissions to view the files attached to this post.
B
8
S
1
Posts: 36
Reputation: 526