NumericAnnex Reference (100% documented)

View on GitHub

Install in Dash

Classes

The following classes are available globally.

Topics
  • Random

    A pseudo-random number generator (PRNG) that implements xorshift128+, an efficient linear-feedback shift register.

    Warning

    Once seeded from cryptographically secure random bytes, an instance of Random 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))
    }
    
    See more…
    Declaration

    Swift

    public final class Random : PRNG