mirror of
https://github.com/GayPizzaSpecifications/voxelotl-engine.git
synced 2025-08-03 13:11:33 +00:00
split split mix sixty four
This commit is contained in:
25
Sources/Voxelotl/Random/SplitMix64.swift
Normal file
25
Sources/Voxelotl/Random/SplitMix64.swift
Normal file
@ -0,0 +1,25 @@
|
||||
public struct SplitMix64: RandomProvider, RandomSeedable {
|
||||
public typealias Output = UInt64
|
||||
public typealias SeedType = UInt64
|
||||
|
||||
public static var min: UInt64 { .max }
|
||||
public static var max: UInt64 { .min }
|
||||
|
||||
private var _state: UInt64
|
||||
|
||||
public init(seed: UInt64) {
|
||||
self._state = seed
|
||||
}
|
||||
|
||||
public mutating func seed(_ value: UInt64) {
|
||||
self._state = value
|
||||
}
|
||||
|
||||
public mutating func next() -> UInt64 {
|
||||
var x = self._state &+ 0x9E3779B97F4A7C15
|
||||
x = (x ^ x &>> 30) &* 0xBF58476D1CE4E5B9
|
||||
x = (x ^ x &>> 27) &* 0x94D049BB133111EB
|
||||
self._state = x ^ x &>> 31
|
||||
return self._state
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user