Skip to content

Instantly share code, notes, and snippets.

@Dupleks
Created January 30, 2020 08:57
Show Gist options
  • Save Dupleks/561f6488d7d08ea7a2a86554c93cb0c8 to your computer and use it in GitHub Desktop.
Save Dupleks/561f6488d7d08ea7a2a86554c93cb0c8 to your computer and use it in GitHub Desktop.
import java.util.Random;
public class Solution {
public static void main(String[] args) {
System.out.println(getRandomNumberInRange(0,185));
System.out.println(getRandomNumberInRange(0,185));
System.out.println(getRandomNumberInRange(0,185));
System.out.println(getRandomNumberInRange(0,185));
System.out.println(getRandomNumberInRange(0,185));
System.out.println(getRandomNumberInRange(0,185));
}
private static int getRandomNumberInRange(int min, int max) {
if (min >= max) {
throw new IllegalArgumentException("max must be greater than min");
}
Random r = new Random();
return r.nextInt((max - min) + 1) + min;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment