Random
public final class Random : PRNGA pseudo-random number generator (PRNG) that implements
xorshift128+, an efficient linear-feedback shift register.
Warning
Once seeded from cryptographically secure random bytes, an instance ofRandom generates high-quality random numbers but is not a
cryptographically secure PRNG.
To generate random numbers, create your own instance of Random with an
internal state seeded from cryptographically secure random bytes:
let random = Random()!
let x = random.uniform() as Int
// You can also pass the desired result type as an argument.
let y = random.uniform(Int.self)
if x > y {
  print("Here's a random value between 0 and 42 (inclusive):")
  print(random.uniform(a: 0, b: 42))
} else {
  print("Here's a random value between -42 and 0 (inclusive):")
  print(random.uniform(a: -42, b: 0))
}
Topics
- 
                  
                  The internal state of the pseudo-random number generator. DeclarationSwift public var state: (UInt64, UInt64)
- 
                  
                  Creates a pseudo-random number generator with the given internal state. DeclarationSwift public init(state: (UInt64, UInt64))Parameters- state
- 
                        The value to be used as the generator’s internal state. 
 
- 
                  
                  Creates a pseudo-random number generator with an internal state seeded using cryptographically secure random bytes. If cryptographically secure random bytes are unavailable, the result is nil.DeclarationSwift public convenience init?()
- 
                  
                  DeclarationSwift public func next() -> UInt64?
- 
                  
                  A pseudo-random number generator (PRNG) that implements xoroshiro128+, a successor toxorshift128+devised by S. Vigna and D. Blackman.Warning Once seeded from cryptographically secure random bytes, an instance ofRandom.Xoroshirogenerates high-quality random numbers but is not a cryptographically secure PRNG.To generate random numbers, create your own instance of Random.Xoroshirowith an internal state seeded from cryptographically secure random bytes:
 See more…let random = Random.Xoroshiro()! let x = random.uniform() as Int // You can also pass the desired result type as an argument. let y = random.uniform(Int.self) if x > y { print("Here's a random value between 0 and 42 (inclusive):") print(random.uniform(a: 0, b: 42)) } else { print("Here's a random value between -42 and 0 (inclusive):") print(random.uniform(a: -42, b: 0)) }DeclarationSwift public final class Xoroshiro : PRNG