Created
November 18, 2022 17:43
-
-
Save kirshiyin89/2d12010fa5630bf3e8d811ed1522509d to your computer and use it in GitHub Desktop.
Random number generator method
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
public static int generateNumberFromRange(int maxRange) throws NoSuchAlgorithmException { | |
Random rand = SecureRandom.getInstanceStrong(); | |
int randomNum; | |
if (maxRange == 100) { | |
randomNum = rand.nextInt(maxRange / 2) * 2; | |
} else { | |
randomNum = rand.nextInt(maxRange / 2) * 2 + 1; | |
} | |
return randomNum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment