Files
swift-argument-parser/Examples/roll/SplitMix64.swift
2020-02-27 15:45:22 -06:00

27 lines
831 B
Swift

//===----------------------------------------------------------*- swift -*-===//
//
// This source file is part of the Swift Argument Parser open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//
struct SplitMix64: RandomNumberGenerator {
private var state: UInt64
init(seed: UInt64) {
self.state = seed
}
mutating func next() -> UInt64 {
self.state &+= 0x9e3779b97f4a7c15
var z: UInt64 = self.state
z = (z ^ (z &>> 30)) &* 0xbf58476d1ce4e5b9
z = (z ^ (z &>> 27)) &* 0x94d049bb133111eb
return z ^ (z &>> 31)
}
}