Skip to content

Comment on Swift Blogparent

Comments

If you have a range of unicode code points that you want to select from, you can generate a random number in that range and then turn it into a one-character string like so:

    let codepoint: UInt32 = ...random choice code here...
    let scalar = UnicodeScalar(codepoint)
    let string = String(scalar)
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.