mardi 16 février 2016

How to chose a variable depending on probability?

I have 35 variables (a1, a2... a34, a35) and each one of them has a number that represents its probability of being picked.

int a1 = 100/i;
int a2 = a1 * 2;
int a3 = a2 * 3;
int a4 = a3 * 4;

With math.Random() I would get a random number between 1 and 100 and the variable that contains that number would be chosen. This last part is the one I can't do.

a1 would have the numbers 0-2.5

a2 would have the numbers 2.6-5

a3 would have the numbers 5.1-7.5




Aucun commentaire:

Enregistrer un commentaire