Last active
June 21, 2020 20:35
-
-
Save kotx/7ef5e708b15482e3c30bc8227ba33c20 to your computer and use it in GitHub Desktop.
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
import random | |
def generate(length): | |
try: | |
get_char = unichr | |
except NameError: | |
get_char = chr | |
# Update this to include code point ranges to be sampled | |
include_ranges = [ | |
(0x30, 0x39), # numbers | |
(0x41, 0x5a), # uppercase chars | |
(0x61, 0x7a), # lowercase chars | |
(0x900, 0x97f), # devanganari (I don't even care, SexualRhino) | |
(0xa8e0, 0xa8fb), # devanganari extended, minus square blocks | |
(0xbc, 0x2af), # weird characters with accents, etc | |
(0x25a0, 0x27ff), # dingbats, etc | |
(0x1f300, 0x1f64f), # emoticons | |
(0x1f910, 0x1f9e6), | |
] | |
alphabet = [ | |
get_char(code_point) for current_range in include_ranges | |
for code_point in range(current_range[0], current_range[1] + 1) | |
] | |
sr = random.SystemRandom() | |
return ''.join(sr.choice(alphabet) for i in range(length)) | |
if __name__ == '__main__': | |
print(generate(5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Available on repl.it here