1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.rng.core.source64;
18
19 import org.apache.commons.rng.core.util.NumberFactory;
20
21
22
23
24
25
26
27
28
29 public class JenkinsSmallFast64 extends LongProvider {
30
31 private long a;
32
33 private long b;
34
35 private long c;
36
37 private long d;
38
39
40
41
42
43
44 public JenkinsSmallFast64(Long seed) {
45 setSeedInternal(seed);
46 }
47
48
49
50
51
52
53 private void setSeedInternal(long seed) {
54 a = 0xf1ea5eedL;
55 b = c = d = seed;
56 for (int i = 0; i < 20; i++) {
57 next();
58 }
59 }
60
61
62 @Override
63 public final long next() {
64 final long e = a - Long.rotateLeft(b, 7);
65 a = b ^ Long.rotateLeft(c, 13);
66 b = c + Long.rotateLeft(d, 37);
67 c = d + e;
68 d = e + a;
69 return d;
70 }
71
72
73 @Override
74 protected byte[] getStateInternal() {
75 return composeStateInternal(NumberFactory.makeByteArray(new long[] {a, b, c, d}),
76 super.getStateInternal());
77 }
78
79
80 @Override
81 protected void setStateInternal(byte[] s) {
82 final byte[][] parts = splitStateInternal(s, 4 * 8);
83
84 final long[] tmp = NumberFactory.makeLongArray(parts[0]);
85 a = tmp[0];
86 b = tmp[1];
87 c = tmp[2];
88 d = tmp[3];
89
90 super.setStateInternal(parts[1]);
91 }
92 }