11/*
22Xoroshiro128+ and Xoroshiro128++ pseudorandom number generators (PRNGs).
3+
4+ References:
5+ https://prng.di.unimi.it
6+ https://prng.di.unimi.it/xoroshiro128plus.c
37*/
48
59import Accelerate
@@ -8,16 +12,20 @@ func rotl(_ x: UInt64, _ k: Int) -> UInt64 {
812 ( x &<< k) | ( x &>> ( 64 &- k) )
913}
1014
11- /// Xoroshiro128+ is a 64-bit pseudorandom number generator (PRNG) for double-precision values .
15+ /// Xoroshiro128+ is a 64-bit pseudorandom number generator (PRNG) for floating-point numbers .
1216public struct Xoroshiro128Plus : RandomNumberGenerator {
1317 private var state : ( UInt64 , UInt64 )
1418
19+ /// Initialize the state of the generator.
20+ /// - Parameter seed: Seed with two 64-bit unsigned integers.
1521 public init ( seed: ( UInt64 , UInt64 ) ? = nil ) {
1622 let a = UInt64 . random ( in: 0 ..< UInt64 . max)
1723 let b = UInt64 . random ( in: 0 ..< UInt64 . max)
1824 state = seed ?? ( a, b)
1925 }
2026
27+ /// Generate a random 64-bit unsigned integer.
28+ /// - Returns: Random 64-bit unsigned integer value.
2129 public mutating func next( ) -> UInt64 {
2230 let s0 = state. 0
2331 var s1 = state. 1
@@ -30,24 +38,28 @@ public struct Xoroshiro128Plus: RandomNumberGenerator {
3038 return result
3139 }
3240
33- /// Generate a random double-precision value from a uniform distribution over [0, 1) which includes zero but
41+ /// Generate a random double-precision value from a uniform distribution in [0, 1) which includes zero but
3442 /// excludes one.
3543 /// - Returns: Random double-precision value.
3644 public mutating func next( ) -> Double {
3745 Double ( next ( ) >> 11 ) * 0x1 . 0 p- 53
3846 }
3947}
4048
41- /// Xoroshiro128++ is a 64-bit pseudorandom number generator (PRNG) for double-precision values .
49+ /// Xoroshiro128++ is a 64-bit pseudorandom number generator (PRNG) for floating-point numbers .
4250public struct Xoroshiro128PlusPlus : RandomNumberGenerator {
4351 private var state : ( UInt64 , UInt64 )
4452
53+ /// Initialize the state of the generator.
54+ /// - Parameter seed: Seed with two 64-bit unsigned integers.
4555 public init ( seed: ( UInt64 , UInt64 ) ? = nil ) {
4656 let a = UInt64 . random ( in: 0 ..< UInt64 . max)
4757 let b = UInt64 . random ( in: 0 ..< UInt64 . max)
4858 state = seed ?? ( a, b)
4959 }
5060
61+ /// Generate a random 64-bit unsigned integer.
62+ /// - Returns: Random 64-bit unsigned integer value.
5163 public mutating func next( ) -> UInt64 {
5264 let s0 = state. 0
5365 var s1 = state. 1
@@ -59,8 +71,8 @@ public struct Xoroshiro128PlusPlus: RandomNumberGenerator {
5971
6072 return result
6173 }
62-
63- /// Generate a random double-precision value from a uniform distribution over [0, 1) which includes zero but
74+
75+ /// Generate a random double-precision value from a uniform distribution in [0, 1) which includes zero but
6476 /// excludes one.
6577 /// - Returns: Random double-precision value.
6678 public mutating func next( ) -> Double {
0 commit comments