# How do I set a value with a certain chance?

Get help using Construct 2

### » Mon Jan 11, 2016 3:52 am

I'd like to know how could I apply probabilities in c2. For example, i have 20% of getting the value 1 Or 50% of getting another value and so on. The reason of this is that i need to create something random but in the same time control this randomness. Also Will be usefull when i add critical strike chance to the character.

Thanks.

Edit: I thought about using the random expression and use numbers from 0 to 100. Like if random(0,100) <= 20 then i have a chance of 20% of doing something. Is this expression reliable to do such thing?
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

### » Mon Jan 11, 2016 10:27 am

kossglobal wrote:I'd like to know how could I apply probabilities in c2. For example, i have 20% of getting the value 1 Or 50% of getting another value and so on. The reason of this is that i need to create something random but in the same time control this randomness. Also Will be usefull when i add critical strike chance to the character.

Thanks.

Edit: I thought about using the random expression and use numbers from 0 to 100. Like if random(0,100) <= 20 then i have a chance of 20% of doing something. Is this expression reliable to do such thing?

That could work, but you could also do something like:

Choose(1,1,2) where you'd have a 66.6% chance of 1 and 33.3% chance of 2

Choose(1,1,2,2,2) where you'd have 40% chance of 1 and 60% chance of 2
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775