-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathPseudoRandomNumberGeneratorTest.java
60 lines (51 loc) · 1.61 KB
/
PseudoRandomNumberGeneratorTest.java
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
60
import java.util.*;
import java.util.random.*;
/**
* Splittable algorithms:
* - L32X64MixRandom
* - L32X64StarStarRandom
* - L64X128MixRandom
* - L64X128StarStarRandom
* - L64X256MixRandom
* - L64X1024MixRandom
* - L128X128MixRandom
* - L128X256MixRandom
* - L128X1024MixRandom
*
* Jumpable algorithms:
* - Xoroshiro128PlusPlus
* - Xoshiro256PlusPlus
*/
public class PseudoRandomNumberGeneratorTest {
private static long SEED = 42L;
public static void main(String[] args) {
testJumpableRandom();
testSplittableRandom();
}
private static void testJumpableRandom() {
RandomGenerator.JumpableGenerator gen = (RandomGenerator.JumpableGenerator) RandomGeneratorFactory.of("Xoroshiro128PlusPlus").create(SEED);
Map<Long, Long> numbers = new HashMap<>();
for (int i = 0; i < 10000; i++) {
var n = gen.nextLong(100);
if (numbers.containsKey(n))
numbers.computeIfPresent(n, (key, val) -> val + 1);
else
numbers.put(n, 1L);
if (i % 100 == 0)
gen.jump();
}
numbers.entrySet().forEach(entry -> System.out.println(entry.getKey() + " -> " + entry.getValue()));
}
private static void testSplittableRandom() {
RandomGenerator.SplittableGenerator gen = (RandomGenerator.SplittableGenerator) RandomGeneratorFactory.of("L32X64MixRandom").create(SEED);
Map<Long, Long> numbers = new HashMap<>();
for (int i = 0; i < 10000; i++) {
var n = gen.nextLong(100);
if (numbers.containsKey(n))
numbers.computeIfPresent(n, (key, val) -> val + 1);
else
numbers.put(n, 1L);
}
numbers.entrySet().forEach(entry -> System.out.println(entry.getKey() + " -> " + entry.getValue()));
}
}