Skip to content

Instantly share code, notes, and snippets.

@leducanhh
Last active November 17, 2020 15:59
Show Gist options
  • Save leducanhh/b76be78b4681fd18cedb0095fb9dfa33 to your computer and use it in GitHub Desktop.
Save leducanhh/b76be78b4681fd18cedb0095fb9dfa33 to your computer and use it in GitHub Desktop.
Better random
float GreaterRandom(float[] lttRate)
{
float total = 0;
foreach (float elem in lttRate)
{
total += elem;
}
float randomPoint = Random.value * total;
for (int i = 0; i < lttRate.Length; i++)
{
if (randomPoint < lttRate[i])
{
return i;
}
else
{
randomPoint -= lttRate[i];
}
}
return lttRate.Length - 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment