mardi 12 décembre 2017

Math.random not giving me a variable within the range I'm looking for?

I'm trying to get a random number between the numbers 57 and 48, 90 and 65, and 122 and 97.

(int) (Math.random * (max-min) + 1);

This usually works, but when I use it to get the above numbers

(int) (Math.random() * (57-48) + 1);
(int) (Math.random() * (90-65) + 1);
(int) (Math.random() * (122-97) + 1);

I wind up with variables that are much to small. (examples: 5 , 14, 3, 15, and 8).

I don't understand why it isn't working with these specific numbers.




Aucun commentaire:

Enregistrer un commentaire