MCPcopy
hub / github.com/kevin-wayne/algs4 / uniformInt

Method uniformInt

src/main/java/edu/princeton/cs/algs4/StdRandom.java:159–162  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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).

Callers 15

timeTrialMethod · 0.95
simpleMethod · 0.95
bipartiteMethod · 0.95
eulerianCycleMethod · 0.95
eulerianPathMethod · 0.95
treeMethod · 0.95
mainMethod · 0.95
FlowNetworkMethod · 0.95
mainMethod · 0.95
EdgeWeightedDigraphMethod · 0.95
mainMethod · 0.95
mainMethod · 0.95

Calls 1

uniformMethod · 0.95

Tested by 1

timeTrialMethod · 0.76