Swift Package Index

RNGExtension

https://github.com/t-ae/rng-extension.git

Swift extension for RandomNumberGenerator


Compatibility

  • 1.0.2, 1.1.0-alpha.6, and master
    5.3
    5.2
    5.1
    5.0
    4.2
  • 1.0.2
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
  • 1.1.0-alpha.6 and master
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS

RNGExtension

Swift exntension for RandomNumberGenerator.

Description

Any RandomNumberGenerator gets uniform: Uniform and normal: Normal. Uniform and Normal have several next functions.

Example

// Get random float number from uniform distribution [10, 20)
let float: Float = Random.default.uniform.next(in: 10..<20)
/// Get random double number from normal distribution N(1, 3^2)
let double: Double = Random.default.normal.next(mu: 1, sigma: 3)

Installation

Add the following setting to your Package.swift.

let package = Package(
    name: "Project",
    dependencies: [
        ...
        .package(url: "https://github.com/t-ae/rng-extension.git", from: "1.0.0"),
    ],
    targets: [
      .target(name: "Project", dependencies: ["RNGExtension", ... ])
    ]
)