Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active January 27, 2020 20:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/9b6cbcebfbf521f5946742bf5e53ec28 to your computer and use it in GitHub Desktop.
Save laevandus/9b6cbcebfbf521f5946742bf5e53ec28 to your computer and use it in GitHub Desktop.
struct SeededRandomNumberGenerator: RandomNumberGenerator {
init(seed: Int) {
srand48(seed)
}
func next() -> UInt64 {
return UInt64(drand48() * Double(UInt64.max))
}
}
var seededGenerator = SeededRandomNumberGenerator(seed: 5)
let random = Int.random(in: -5...5, using: &seededGenerator)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment