Random

The Random module deals with random data generation including random number generation.

Data Generator

The DataGenerator class powers all of the random data generators.

Implementations

  • OSRandom: Provides a random data generator using a platform-specific method.
  • URandom provides random data generation based on the /dev/urandom file.
  • CryptoRandom from the Crypto module provides cryptographically-secure random data using OpenSSL.
  1. let random: DataGenerator ...
  2. let data = try random.generateData(bytes: 8)

Generate

DataGenerators are capable of generating random primitive types using the generate(_:) method.

  1. let int = try OSRandom().generate(Int.self)
  2. print(int) // Int