Skip to content

Instantly share code, notes, and snippets.

@kirshiyin89
Created November 18, 2022 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirshiyin89/2d12010fa5630bf3e8d811ed1522509d to your computer and use it in GitHub Desktop.
Save kirshiyin89/2d12010fa5630bf3e8d811ed1522509d to your computer and use it in GitHub Desktop.
Random number generator method
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