Skip to content

Commit

Permalink
Add init to ReseedingRandomGenerator using default
Browse files Browse the repository at this point in the history
Uses default instance of DeviceRandom and ARC4Random. This is the common
(and only in the case of ARC4Random) way to use these generators. So it
makes sense that when initializing without a specified reseeder, these
values are used.
  • Loading branch information
nvzqz committed Mar 24, 2017
1 parent a7d1b9b commit da57645
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ extension ReseedingRandomGenerator where Reseeder: SeedableFromOtherRandomGenera

}

#if swift(>=3.1)
extension ReseedingRandomGenerator where Reseeder == DeviceRandom {

/// Creates an instance with `threshold` by instantiating `base` from `DeviceRandom.default`.
public init(threshold: Int = Base.reseedingThreshold) {
self.init(reseeder: .default, threshold: threshold)
}

}

extension ReseedingRandomGenerator where Reseeder == ARC4Random {

/// Creates an instance with `threshold` by instantiating `base` from `ARC4Random.default`.
public init(threshold: Int = Base.reseedingThreshold) {
self.init(reseeder: .default, threshold: threshold)
}

}
#endif

extension Int {
@inline(__always)
fileprivate func _saturatingAddPositive(_ other: Int) -> Int {
Expand Down

0 comments on commit da57645

Please sign in to comment.