I wanted to generate a random number using Random() and make it unchanged with-in a given execution irrespective of number of calls to that method.
How can I do it?
The following explanation would make my question more clear.
I am generating a randomNumber within a range by the following method.
private int generateARandomNumber(int min, int max) {
// min = 101;
// max = 10001;
Random random = new Random();
myRandomNum = random.nextInt(max - min) + min ;
return myRandomNum;
}
How can I assign the value returned to a constant like
MYID = generateARandomNumber(101,10001),
which will remain unchanged for this execution?
Aucun commentaire:
Enregistrer un commentaire