Help needed with probability

i am trying to have 3 encounters be possible but i want some to have a higher probability than others i have looked at these pages

http://docs.unity3d.com/Manual/RandomNumbers.html
https://www.reddit.com/r/Unity3D/comments/2a6bfz/how_to_set_probability_of_an_event_via_inspector/

but i still cant figure out how to do this can someone help me cause i cant find much information about this subject

Perhaps not the best way, but this is how I do it :

int roll = Random.Range (0, 100);
if(roll >= 80) {
//scenario 1, 20% chance of occurring
}
else if (roll >= 50) {
//scenario 2, 30% chance of occurring
}
else {
//scenario 3, 50% chance of occurring
}

This is a pretty common need. There are fancier ways to do it, but for a simple case like this, the easiest is to just generate a random number between 0 and 100, and then use an if/else if/else block to carve that 0-100 range into whatever chunks you want. For example:

int roll = Random.Range(0, 100)
if (roll < 50) {
    DoOneEncounter();
} else if (roll < 80) {
    DoAnotherEncounter();
} else {
    DoSomethingElse();
}

So this gives the three possibilities a 50%, 30%, and 20% chance respectively.

EDIT: @ADNCG , you beat me by that → ← much! :slight_smile:

1 Like

that is what i used to do but that is not a real probability its just luck since its compleetly random i want to have a probability and not random

“Probability…”

1 Like