1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
| long seed = 736418123831L;
Random r = new Random(seed);
int[] hashFreq = new int[1000];
long hashA = r.nextInt(Integer.MAX_VALUE); // 1048587624;
long hashB = r.nextInt(Integer.MAX_VALUE); // 1380959055;
for(int i = 0; i < 10000; ++i) {
long res = ((hashA * i + hashB) & ((1L << 31) - 1)) % 1000;
hashFreq[(int)res]++;
}
for(int i = 0; i < 1000; ++i) {
System.out.println(i + " " + hashFreq[i]);
}
/*
Output:
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 78
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 77
16 0
17 0
18 0
19 0
20 0
21 0
22 0
23 85
24 0
25 0
26 0
27 0
28 0
29 0
30 0
31 78
32 0
33 0
34 0
35 0
36 0
37 0
38 0
39 78
40 0
...
*/
|