diff --git a/Sources/RandomKit/Types/RandomGenerator/ChaCha.swift b/Sources/RandomKit/Types/RandomGenerator/ChaCha.swift index e17c78b..efc4a77 100644 --- a/Sources/RandomKit/Types/RandomGenerator/ChaCha.swift +++ b/Sources/RandomKit/Types/RandomGenerator/ChaCha.swift @@ -33,10 +33,19 @@ /// [2]: https://en.wikipedia.org/wiki/Salsa20#ChaCha_variant /// [3]: https://doc.rust-lang.org/rand/rand/chacha/struct.ChaChaRng.html public struct ChaCha: RandomBytesGenerator, Seedable, SeedableFromSequence, SeedableFromRandomGenerator { - /// The seed type. public typealias Seed = [UInt32] + /// The seed value + public var seed: Seed { + return [ + _state.0, _state.1, _state.2, _state.3, + _state.4, _state.5, _state.6, _state.7, + _state.8, _state.9, _state.10, _state.11, + _state.12, _state.13, _state.14, _state.15, + ] + } + /// The seed sequence's element type. public typealias SeedSequenceElement = UInt32 diff --git a/Sources/RandomKit/Types/RandomGenerator/MersenneTwister.swift b/Sources/RandomKit/Types/RandomGenerator/MersenneTwister.swift index b642ebf..a370705 100644 --- a/Sources/RandomKit/Types/RandomGenerator/MersenneTwister.swift +++ b/Sources/RandomKit/Types/RandomGenerator/MersenneTwister.swift @@ -43,6 +43,10 @@ /// /// [MT]: https://en.wikipedia.org/wiki/Mersenne_Twister public struct MersenneTwister: RandomBytesGenerator, Seedable, SeedableFromRandomGenerator { + /// The seed value. + public var seed: UInt64 { + return _state.0 + } /// The number of `UInt64` values in a `_State`. private static let _stateCount: Int = 312 diff --git a/Sources/RandomKit/Types/RandomGenerator/Seedable.swift b/Sources/RandomKit/Types/RandomGenerator/Seedable.swift index 0c06bd2..a39d35a 100644 --- a/Sources/RandomKit/Types/RandomGenerator/Seedable.swift +++ b/Sources/RandomKit/Types/RandomGenerator/Seedable.swift @@ -31,6 +31,9 @@ public protocol Seedable { /// The seed type. associatedtype Seed + /// Current seed value. + var seed: Seed { get } + /// Creates an instance from `seed`. init(seed: Seed) diff --git a/Sources/RandomKit/Types/RandomGenerator/Xoroshiro.swift b/Sources/RandomKit/Types/RandomGenerator/Xoroshiro.swift index 645a05f..28d3ff3 100644 --- a/Sources/RandomKit/Types/RandomGenerator/Xoroshiro.swift +++ b/Sources/RandomKit/Types/RandomGenerator/Xoroshiro.swift @@ -46,6 +46,13 @@ /// [1]: http://xoroshiro.di.unimi.it/ /// [2]: http://xoroshiro.di.unimi.it/xoroshiro128plus.c public struct Xoroshiro: RandomBytesGenerator, Seedable, SeedableFromRandomGenerator { + /// The seed type. + public typealias Seed = (UInt64, UInt64) + + /// The seed value. + public var seed: Seed { + return _state + } /// A default global instance seeded with `DeviceRandom.default`. public static var `default` = seeded @@ -54,10 +61,10 @@ public struct Xoroshiro: RandomBytesGenerator, Seedable, SeedableFromRandomGener public static var defaultReseeding = reseeding /// The internal state. - private var _state: (UInt64, UInt64) + private var _state: Seed /// Creates an instance from `seed`. - public init(seed: (UInt64, UInt64)) { + public init(seed: Seed) { _state = seed } diff --git a/Sources/RandomKit/Types/RandomGenerator/Xorshift.swift b/Sources/RandomKit/Types/RandomGenerator/Xorshift.swift index e0f1c2c..f533380 100644 --- a/Sources/RandomKit/Types/RandomGenerator/Xorshift.swift +++ b/Sources/RandomKit/Types/RandomGenerator/Xorshift.swift @@ -32,6 +32,13 @@ /// [1]: http://www.jstatsoft.org/v08/i14/paper /// [2]: https://doc.rust-lang.org/rand/rand/struct.XorShiftRng.html public struct Xorshift: RandomBytesGenerator, Seedable, SeedableFromRandomGenerator { + /// The seed type. + public typealias Seed = (UInt32, UInt32, UInt32, UInt32) + + /// The seed value. + public var seed: Seed { + return (x, y, z, w) + } /// A default global instance seeded with `DeviceRandom.default`. public static var `default` = seeded @@ -49,7 +56,7 @@ public struct Xorshift: RandomBytesGenerator, Seedable, SeedableFromRandomGenera /// Creates an instance from `seed`. /// /// - precondition: `seed` is nonzero. - public init(seed: (UInt32, UInt32, UInt32, UInt32)) { + public init(seed: Seed) { (x, y, z, w) = seed } diff --git a/Sources/RandomKit/Types/RandomGenerator/XorshiftStar.swift b/Sources/RandomKit/Types/RandomGenerator/XorshiftStar.swift index e890d3d..0788353 100644 --- a/Sources/RandomKit/Types/RandomGenerator/XorshiftStar.swift +++ b/Sources/RandomKit/Types/RandomGenerator/XorshiftStar.swift @@ -29,7 +29,6 @@ /// /// [1]: http://xoroshiro.di.unimi.it/xorshift1024star.c public struct XorshiftStar: RandomBytesGenerator, Seedable, SeedableFromRandomGenerator { - /// The seed type. public typealias Seed = ( UInt64, UInt64, UInt64, UInt64, @@ -38,6 +37,11 @@ public struct XorshiftStar: RandomBytesGenerator, Seedable, SeedableFromRandomGe UInt64, UInt64, UInt64, UInt64 ) + /// The seed value. + public var seed: Seed { + return _state + } + private typealias _State = _Array16 private static var _jump: _State = (