Skip to content

Instantly share code, notes, and snippets.

@molcay
Last active October 21, 2018 20:36
Show Gist options
  • Select an option

  • Save molcay/40017e8d170c28d99e632f29ecd633ee to your computer and use it in GitHub Desktop.

Select an option

Save molcay/40017e8d170c28d99e632f29ecd633ee to your computer and use it in GitHub Desktop.

Revisions

  1. molcay revised this gist Oct 21, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion unique_id_generation.py
    Original file line number Diff line number Diff line change
    @@ -30,4 +30,4 @@ def generate_from_pattern(self, pattern, sep=' '):
    uuid_format = [8, 4, 4, 4, 12]
    rnd = Random()
    uuid_with_all_ascii_letters_and_digits = rnd.generate_from_pattern(uuid_format, '-')
    print(a)
    print(uuid_with_all_ascii_letters_and_digits)
  2. molcay created this gist Oct 21, 2018.
    33 changes: 33 additions & 0 deletions unique_id_generation.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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(a)