- Home /
Semi-Random Or Engine
Hello Everyone, I want to be able to pick a random number within a certain range, and I am aware of random.range();
However, I want to be able to have, say, a 75% chance of 1-20, 15% chance of 21-30, 10% chance of 31-35, if that makes sense. Thank you.
Answer by Bunny83 · Mar 25, 2016 at 01:12 AM
Pseudo random number generators have a uniform number distribution. You have to do it in two seperate steps. First use a random float value to define your area and then do another Random.Range to get the actual number
int GetValue()
{
float n = Random.value;
if (n < 0.75f)
return Random.Range(1, 21);
n -= 0.75f;
if (n < 15f)
return Random.Range(21, 31);
return Random.Range(31, 36);
}
Your answer
Follow this Question
Related Questions
Non-repeating random number generator crashing unity 1 Answer
Need help with generating random Multiplier,Need help with generating random multipliers 0 Answers
Distribute terrain in zones 3 Answers
How to make enemy prefab spawn at random times between 1.0f to 10.0f. 1 Answer
How can I randomly create a number and then delete it to stop repeating 3 Answers