Skip to content

Commit 6ca706e

Browse files
authored
Merge pull request #24357 from palimondo/prng-splitmix64
[benchmark] Add SplitMix64 PRNG
2 parents d7856dc + d2a47db commit 6ca706e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

benchmark/utils/TestsUtils.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,29 @@ public func Random() -> Int64 {
221221
return lfsrRandomGenerator.randInt()
222222
}
223223

224+
// This is a fixed-increment version of Java 8's SplittableRandom generator.
225+
// It is a very fast generator passing BigCrush, with 64 bits of state.
226+
// See http://dx.doi.org/10.1145/2714064.2660195 and
227+
// http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html
228+
//
229+
// Derived from public domain C implementation by Sebastiano Vigna
230+
// See http://xoshiro.di.unimi.it/splitmix64.c
231+
public struct SplitMix64: RandomNumberGenerator {
232+
private var state: UInt64
233+
234+
public init(seed: UInt64) {
235+
self.state = seed
236+
}
237+
238+
public mutating func next() -> UInt64 {
239+
self.state &+= 0x9e3779b97f4a7c15
240+
var z: UInt64 = self.state
241+
z = (z ^ (z &>> 30)) &* 0xbf58476d1ce4e5b9
242+
z = (z ^ (z &>> 27)) &* 0x94d049bb133111eb
243+
return z ^ (z &>> 31)
244+
}
245+
}
246+
224247
@inlinable // FIXME(inline-always)
225248
@inline(__always)
226249
public func CheckResults(

0 commit comments

Comments
 (0)