Skip to content

Request: Random.generate(hexCharacterCount:) #18

@twostraws

Description

@twostraws

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.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions