Skip to content

Instantly share code, notes, and snippets.

@JadenGeller
Created November 11, 2023 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JadenGeller/250347fb6403d6256ee431c97f3d3eda to your computer and use it in GitHub Desktop.
Save JadenGeller/250347fb6403d6256ee431c97f3d3eda to your computer and use it in GitHub Desktop.
uses GameplayKit GKMersenneTwisterRandomSource
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