Well, my point was that some of these "low-quality" RNG APIs, especially the obscure ones, are probably not much of a security risk now that we have first-class a RNG in the standard library. But upon consideration, I know it's Apple's right to make its own business decisions about what to expose with the Darwin
module, and opinions voiced here probably won't change those decisions.
In the meantime, I'm using this:
/// A linear congruential pseudo-random number generator.
struct LinearCongruential: RandomNumberGenerator {
/// The last value returned by `self.next`, or what `self` was seeded with.
private var lastValue: UInt64
/// Creates an instance with the given seed.
///
/// Instances created with the same seed produce the same sequence of
/// pseuedo-random results from `next()`.
init(seed: UInt64 = 0) {
lastValue = seed
}
/// Returns a value from a uniform, independent distribution of binary data.
mutating func next() -> UInt64 {
// A "good value" chosen from https://arxiv.org/pdf/2001.05304.pdf (Steele,
// Guy; Vigna, Sebastiano (15 January 2020). "Computationally easy,
// spectrally good multipliers for congruential pseudorandom number
// generators". arXiv:2001.05304 [cs.DS].)
let a: UInt64 = 0xaf251af3b0f025b5
// As long as “m”, the modulus value, is a power of 2, the generator is
// insensitive to the value of c, provided they are relatively prime.
let c: UInt64 = 1
lastValue = lastValue &* a &+ c
return lastValue
}
}