Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Random.generate(hexCharacterCount:) #18

Open
twostraws opened this issue Jan 23, 2017 · 0 comments
Open

Request: Random.generate(hexCharacterCount:) #18

twostraws opened this issue Jan 23, 2017 · 0 comments

Comments

@twostraws
Copy link

The Random.generate(byteCount:) is a useful way of generating random bytes, but in my own work I found I was mostly using it to generate random strings for encryption purposes. This meant every call to Random.generate(byteCount:) was followed by a call to CryptoUtils.hexString(from:) to get a Swift string rather than just bytes.

If you could implement a Random.generate(hexCharacterCount:) method that combined the two together, it would be most appreciated. If this were combined with #17, then this code:

if let randomBytes = try? Random.generate(byteCount: 64) {
    randomString = CryptoUtils.hexString(from: randomBytes)
} else {
    randomString = generateMyOwnRandomStringSomehow()
}

Would become simply this:

randomString = Random.generate(hexCharacterCount: 128)

(Note: There may well be a better name for this method.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants