Created
November 11, 2023 20:25
-
-
Save JadenGeller/250347fb6403d6256ee431c97f3d3eda to your computer and use it in GitHub Desktop.
uses GameplayKit GKMersenneTwisterRandomSource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import GameplayKit | |
struct DeterministicRandomNumberGenerator: RandomNumberGenerator { | |
private let randomSource: GKMersenneTwisterRandomSource | |
init(seed: UInt64) { | |
randomSource = GKMersenneTwisterRandomSource(seed: seed) | |
} | |
mutating func next() -> UInt64 { | |
let upperBits = UInt64(UInt32(bitPattern: Int32(randomSource.nextInt()))) << 32 | |
let lowerBits = UInt64(UInt32(bitPattern: Int32(randomSource.nextInt()))) | |
return upperBits | lowerBits | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment