Last active
April 23, 2022 16:30
-
-
Save iandundas/59303ab6fd443b5eec39 to your computer and use it in GitHub Desktop.
Random Emoji
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns a random Emoji 🌿 | |
extension String{ | |
func randomEmoji()->String{ | |
let range = 0x1F601...0x1F64F | |
let ascii = range.startIndex + Int(arc4random_uniform(UInt32(range.count))) | |
let emoji = String(UnicodeScalar(ascii)) | |
return emoji | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Heyo,
I've updated my approach to allow multiple discontiguous ranges of emojis. This allows you to make use of more emoji.
usage:
https://gist.github.com/cellularmitosis/d425aae5f1a2e5d9bfa1d4c1a5968d22#gistcomment-3644352