Last active
October 21, 2018 20:36
-
-
Save molcay/40017e8d170c28d99e632f29ecd633ee to your computer and use it in GitHub Desktop.
based on https://stackoverflow.com/a/48965444
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 as r | |
import string | |
def randomized_default(): | |
domains = [string.ascii_uppercase, string.ascii_lowercase, string.digits] | |
r.shuffle(domains) | |
as_list = list(''.join(domains)) | |
r.shuffle(as_list) | |
return ''.join(as_list) | |
class Random: | |
_default_str_seq = randomized_default() | |
def __init__(self, str_seq=_default_str_seq): | |
self.str_seq = str_seq | |
def generate_from_pattern(self, pattern, sep=' '): | |
random_str_parts = [] | |
for part in pattern: | |
str_part = "" | |
for i in range(0, part): | |
str_part += str(r.choice(self.str_seq)) | |
random_str_parts.append(str_part) | |
return sep.join(random_str_parts) | |
uuid_format = [8, 4, 4, 4, 12] | |
rnd = Random() | |
uuid_with_all_ascii_letters_and_digits = rnd.generate_from_pattern(uuid_format, '-') | |
print(uuid_with_all_ascii_letters_and_digits) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment