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 theCrypto
module provides cryptographically-secure random data using OpenSSL.
let random: DataGenerator ... let data = try random.generateData(bytes: 8)
Generate¶
DataGenerator
s are capable of generating random primitive types using the generate(_:)
method.
let int = try OSRandom().generate(Int.self) print(int) // Int