dimanche 17 janvier 2016

Java: Difference between these 2 ways of finding Random Numbers?

For example, if I were to generate random numbers between 5 and 50, I know I could write the code as either:

ranNum = (int)Math.random()*(50-5+1)+5;

Or

ranNum = Math.round(Math.random()*(50-5))+5;

In terms of the process to generate the random numbers, what is the difference between the two? And which would be faster?




Aucun commentaire:

Enregistrer un commentaire