Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making a random int
#2
[code2=java]public static int randInt(int min, int max) {

// Usually this can be a field rather than a method variable
Random rand = new Random();

// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
int randomNum = rand.nextInt((max - min) + 1) + min;

return randomNum;
}[/code2]

Source from http://stackoverflow.com/questions/36368...-with-java


Messages In This Thread
Making a random int - by mustafa6155 - 03-23-2014, 03:52 AM
Re: Making a random int - by Fusion - 03-29-2014, 10:54 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)