Files
EcgSynKit/Sources/ECGSynKit/SplitMix64.swift
2024-11-04 10:48:09 -06:00

22 lines
521 B
Swift

struct SplitMix64 : RandomNumberGenerator {
public typealias State = UInt64
public private(set) var state: State
init(state: UInt64) {
self.state = state
}
public mutating func next() -> UInt64 {
state &+= 0x9E3779B97F4A7C15
var z = state
z = (z ^ (z >> 30)) &* 0xBF58476D1CE4E5B9
z = (z ^ (z >> 27)) &* 0x94D049BB133111EB
return z ^ (z >> 31)
}
public mutating func nextDouble() -> Double {
Double(next() >> 11) * 0x1.0p-53
}
}