Skip to content

Instantly share code, notes, and snippets.

@kmosher
Created July 31, 2014 15:52
Show Gist options
  • Save kmosher/fce89faf25f6ec5413f6 to your computer and use it in GitHub Desktop.
Save kmosher/fce89faf25f6ec5413f6 to your computer and use it in GitHub Desktop.
Random Gmail Emojis
#!/usr/bin/python
"""
Return a random unicode character likely to render as a valid emoji in gmail
Ranges are taken from
http://www.unicode.org/~scherer/emoji4unicode/20090804/utc.html
"""
import random
google_emoji_ranges = {
'0': ('00', '5B'),
'1': ('90', 'E2'),
'3': ('20', '5B'),
'4': ('B0', 'FF'),
'5': ('00', '53'),
'7': ('D0', 'FF'),
'8': ('00', '3A'),
'9': ('60', '88'),
'A': ('F0', 'FF'),
'B': ('00', 'A1'),
}
more_sig_byte = random.choice(google_emoji_ranges.keys())
# Since the ranges are different sizes, all characters don't have
# an equal probability of being chosen. I don't care.
min_range, max_range = google_emoji_ranges[more_sig_byte]
least_sig_bytes = random.randint(int(min_range, 16), int(max_range, 16))
print unichr(
int('FE000', 16) +
int(more_sig_byte + '00', 16) +
least_sig_bytes
).encode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment