samedi 21 novembre 2015

Is this a valid way to assign a random number to a variable? [duplicate]

This question already has an answer here:

I have seen a lot of different ways to generate random numbers in between a certain range. Just today I came across the following piece of code. but upon doing research, I did not see anybody describe it this way.

Random ran = new Random();
int j = ran.nextInt(5+10);

My question is, does the code above assign a random integer to j between the numbers of 5 and 10? If so, what if you wrote the second line of code like this int j = rgen.nextInt(10+5);




Aucun commentaire:

Enregistrer un commentaire