-
Notifications
You must be signed in to change notification settings - Fork 48
Open
Labels
Description
When I need to generate some random data for a string, I'd run code like this:
if let randomBytes = try? Random.generate(byteCount: 64) {
randomString = CryptoUtils.hexString(from: randomBytes)
} else {
randomString = generateMyOwnRandomStringSomehow()
}
If I'm trying to generate something important, e.g. a salt, the generateMyOwnRandomStringSomehow()
is a weak point because it relies on users to have some idea of PRNG techniques. Is it possible to make Random.generate() always return a value, perhaps by implementing a second generation algorithm that can be used if the preferred algorithm fails?
(Note: the answer may well be "No", but I'm following the "if you don't ask, you don't get" approach.")