-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathXORShift64Star.cs
More file actions
33 lines (26 loc) · 827 Bytes
/
Copy pathXORShift64Star.cs
File metadata and controls
33 lines (26 loc) · 827 Bytes
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
namespace AlgorithmsAndDataStructures.Algorithms.PseudorandomNumberGenerators;
public class XorShift64Star
{
// This value has the only requirement of not being zero.
private const long Seed = 429496729667111;
// This number is a part of an algorithm.
private const long Multiplier = 2685821657736338717;
private long lastGeneratedValue;
public XorShift64Star()
{
lastGeneratedValue = GenerateInternal(Seed);
}
public long Generate()
{
lastGeneratedValue = GenerateInternal(lastGeneratedValue);
return lastGeneratedValue;
}
private static long GenerateInternal(long previous)
{
var x = previous;
x ^= x >> 12;
x ^= x << 25;
x ^= x >> 27;
return x * Multiplier;
}
}