How to increase chances of the last value of a random range?
When you used "Random.Range ( 0, anIntNumber)", did you notice that the last value in this range is very rare to occur. However, I need it to happen more often than other values. How can I change the occurring chances on this specific value?
Answer by NoseKills · Aug 09, 2016 at 06:00 PM
Actually it will never return the second parameter. Random.Range with integers excludes the second parameter.
With floats the second parameter is included in the range
If you need the last parameter to be included in the results, you just have to increase the range by 1.
If you need a specific value to occurr even more often, there's no shortcut. You just have to resort to old school math. For example
var random = Random.Range(0, 5 + 1); // 0 to 5
var random1 = Random.Range(0, 5 + 2);
if (random1 > 5)
random1 = 5;
// 6 possible values, 2 of which are '5'
Thank you very much for your answer! It solved my problem!
Your answer
![](https://koobas.hobune.stream/wayback/20220612090500im_/https://answers.unity.com/themes/thub/images/avi.jpg)