Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int max = 3;
- static double[] chances = null;
- internal static int Choose(this List<MenuSceneInfo> list, int hash)
- {
- if (chances == null)
- {
- chances = new double[list.Count];
- for (int i = 0; i < chances.Length; i++)
- {
- chances[i] = 100d / chances.Length;
- }
- }
- double random = Math.Pow(hash, 0.5) % 100d;
- double sum = 0;
- for (int i = 0; i < chances.Length; i++)
- {
- sum += chances[i];
- if (random < sum)
- {
- double penalty = Math.Min(chances[i], (100d / max) / chances.Length);
- double bonus = penalty / (chances.Length - 1);
- for (int j = 0; j < chances.Length; j++)
- {
- chances[j] += bonus;
- }
- chances[i] = chances[i] - bonus - penalty;
- return i;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement