Returns a random integer uniformly in [0, n). @param n number of possible integers @return a random integer uniformly between 0 (inclusive) and n (exclusive) @throws IllegalArgumentException if n <= 0
(int n)
| 157 | * @throws IllegalArgumentException if {@code n <= 0} |
| 158 | */ |
| 159 | public static int uniformInt(int n) { |
| 160 | if (n <= 0) throw new IllegalArgumentException("argument must be positive: " + n); |
| 161 | return random.nextInt(n); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Returns a random long integer uniformly in [0, n). |