In this comment in another question, dimo414 states that one of the problems with the OP's code is that it will generate random numbers non-uniformly. So I wonder why this is? Is it inherent the the particular algorithm? Or is it something about Math.random()
itself? Is it because of the floating-point representation of the numbers chosen in the interval [0.0, 1.0)?
p.s. I understand the proposed answer to use Random.nextInt()
. I also want to know more about the flaws of using Math.random()
.
Aucun commentaire:
Enregistrer un commentaire