. Advertisement .
..3..
. Advertisement .
..4..
I need to generate random number between 1000 And 9999. Here is my code:
public static int getRandomNumber (int max) {
return (int) (Math.random()*max);
}
Do you have a better suggestion, please suggest
/* min = 1000; max = 9999 */
public static int getRandomNumber (int min, int max) {
int randomNumber = ( int )( Math.random() * max );
if( randomNumber <= min ) {
randomNumber = randomNumber + min;
}
return randomNumber;
}
1 Answer