I believe you've made a mistake in your formula, verify the logic in it. (In case you're wondering, the mistake lies in the fact that you're not adding the rates up)
@Will:
Basically what you need to do is generate a random number between 0 and 100.
You have either a list, an array or whatever.. of all the rates (You really only need the four, "no charms" is unnecessary).
From here on, you basically do something similar to:
Code:
public static final int getIndex(final int[] charmsArrayOrList) {
final int roll = (int) (Math.random() * 100) + 1;//returns a value from 1 to 100.
int chance = 0, index = 0;
for (int c : charmsArrayOrList) {
if ((chance += c) >= roll)
return index;
index++;
}
return -1;//Should never happen unless the value of the array is below 100.
}
If you try the code I provided, you'll get some results like:
System.out.println(getIndex(new int[] { 73, 12, 6, 4, 5 }));
->
Say roll in the method returns 86, the value returned will be 2 AKA number 6 (73 + 12 -> 85; 85 < 86 therefore continue. 85 + 6 -> 91. 91 > 86 therefore return the index AKA 2.