1
2
3
4
5
6 package io.github.olyutorskii.aletojio.shrink;
7
8 import io.github.olyutorskii.aletojio.rng.RndInt32;
9 import java.util.ArrayList;
10 import java.util.Arrays;
11 import java.util.Collection;
12 import java.util.Objects;
13
14
15
16
17
18
19 @SuppressWarnings("serial")
20 public class XorMixer implements RndInt32 {
21
22 private final Collection<RndInt32> rnds;
23
24
25
26
27
28
29
30
31
32 public XorMixer(Collection<RndInt32> rndColl)
33 throws NullPointerException, IllegalArgumentException {
34 super();
35 Objects.requireNonNull(rndColl);
36
37 if (rndColl.isEmpty()) {
38 throw new IllegalArgumentException();
39 }
40
41 for (RndInt32 rnd : rndColl) {
42 Objects.requireNonNull(rnd);
43 }
44
45 this.rnds = new ArrayList<>(rndColl);
46
47 return;
48 }
49
50
51
52
53
54
55
56
57 public XorMixer(RndInt32... rndVec)
58 throws NullPointerException, IllegalArgumentException {
59 this(Arrays.asList(rndVec));
60 return;
61 }
62
63
64
65
66
67
68 @Override
69 public int nextInt32() {
70 int result = 0x00;
71
72 for (RndInt32 rnd : this.rnds) {
73 result ^= rnd.nextInt32();
74 }
75
76 return result;
77 }
78
79 }