Created
April 14, 2020 01:51
-
-
Save koizumihiroo/9a8117dc45036af25d154c63ee933021 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 collections | |
import random | |
import string | |
from typing import List | |
numbers: str = string.digits | |
lowers: str = string.ascii_lowercase | |
uppers: str = string.ascii_uppercase | |
def gen(length: int) -> str: | |
# b is bulkhead choice | |
b = sorted(random.sample(range(length - 1), k=2)) | |
x1 = b[0] + 1 | |
x2 = b[1] - b[0] | |
x3 = length - b[1] - 1 | |
n = random.choices(numbers, k=x1) | |
l = random.choices(lowers, k=x2) | |
u = random.choices(uppers, k=x3) | |
seq = n + l + u | |
return ''.join(random.sample(seq, k=len(seq))) | |
def count_distribution(gens): | |
elems = [x for y in gens for x in y] | |
counts = collections.Counter(elems) | |
return [counts, {x:sum([counts[y] for y in eval(x)]) for x in ["numbers", "lowers", "uppers"]}] | |
if __name__ == "__main__": | |
random.seed(1) | |
print(count_distribution((gen(15) for _ in range(100_000)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment