dimanche 29 mai 2016

Don't understand how Math.random() works in java

Why does the following code prints just 25?

while(true) {
    int pos = (int) (Math.random() * (26 ));
    if (pos > 24)
        System.out.println(pos);
}

If Math.random() returns a number from 0 to 1 then shouldn't the code above print also 26 (1*26 = 26)?




Aucun commentaire:

Enregistrer un commentaire