Created
January 9, 2013 11:21
-
-
Save iezg/4492410 to your computer and use it in GitHub Desktop.
Generating random number in a range with Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example assumes these variables have been initialized | |
// above, e.g. as method parameters, fields, or otherwise | |
int min, max; | |
// nextInt is normally exclusive of the top value, | |
// so add 1 to make it inclusive | |
Random rand = new Random(); | |
int randomNum = rand.nextInt(max - min + 1) + min; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment