MCPcopy Create free account
hub / github.com/algorithmzuo/algorithm-journey / random

Method random

src/class129/Code04_FindNear.java:122–131  ·  view source on GitHub ↗
(int v)

Source from the content-addressed store, hash-verified

120 // 随机生成arr[1...n]确保没有重复数值
121 // 为了测试
122 public static void random(int v) {
123 HashSet<Integer> set = new HashSet<>();
124 for (int i = 1, cur; i <= n; i++) {
125 do {
126 cur = (int) (Math.random() * v * 2) - v;
127 } while (set.contains(cur));
128 set.add(cur);
129 arr[i] = cur;
130 }
131 }
132
133 // 如下四个数组用来做备份
134 public static int[] a = new int[MAXN];

Callers 3

mainMethod · 0.95
randomArrayMethod · 0.45
mainMethod · 0.45

Calls 2

containsMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected