- Home /
Percentage for random
Hello! I want to instantiate obj A , B , C randomly. However, I want to set that the percentage that instantiate obj A is higher than B n C. For ex: A = 70 %, B =20 %, C = 10. So how can I achieve that? Thanks in advance!
Comment
Answer by syclamoth · Oct 10, 2011 at 05:17 AM
How about
whateverType[] thingiesArray = new whateverType[]{A, A, A, A, A, A, A, B, B ,C};
That way, there's a higher chance of certain elements being picked.
Or, you could have a weighted random value like this-
float value = Random.value;
if(value > 0.9f)
{
C;
} else if(value > 0.7f){
B;
} else {
A;
}
There are probably more ways... Additional answers are welcome!
Your answer
![](https://koobas.hobune.stream/wayback/20220613002836im_/https://answers.unity.com/themes/thub/images/avi.jpg)