123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- from random import random
- import tabulate
- # noinspection SpellCheckingInspection
- salt = 'orderer_is_a_cool_application_]{][{²$%WT§$%GV§$%SF$%&S$%FGGFHBDHJZIF254325'
- chars = [str(d) for d in range(1, 10)]
- ps = [1. for _ in chars]
- # the first number is absolute and the second relative
- letter_dist = [("E", 21912, 12.02), ("T", 16587, 9.1), ("A", 14810, 8.12), ("O", 14003, 7.68), ("I", 13318, 7.31),
- ("N", 12666, 6.95), ("S", 11450, 6.28), ("R", 10977, 6.02), ("H", 10795, 5.92), ("D", 7874, 4.32),
- ("L", 7253, 3.98), ("U", 5246, 2.88), ("C", 4943, 2.71), ("M", 4761, 2.61), ("F", 4200, 2.3),
- ("Y", 3853, 2.11), ("W", 3819, 2.09), ("G", 3693, 2.03), ("P", 3316, 1.82), ("B", 2715, 1.49),
- ("V", 2019, 1.11), ("K", 1257, 0.69), ("X", 315, 0.17), ("Q", 205, 0.11), ("J", 188, 0.1),
- ("Z", 128, 0.07), ]
- sp = sum(ps)
- for row in letter_dist:
- chars.append(row[0])
- ps.append(float(row[2]))
- ps = [p / sum(ps) for p in ps]
- def choice(sequence, probabilities):
- # if sum(probabilities) != 1:
- # raise AssertionError('Probabilities must sum up to 1')
- r = random()
- for idx, c in enumerate(sequence):
- r -= probabilities[idx]
- if r < 0:
- return c
- raise AssertionError('Probabilities must sum up to 1')
- def random_chars(count):
- return ''.join(choice(chars, probabilities=ps) for _ in range(count))
- def str2bool(v):
- v = str(v).strip().lower()
- if v in ["yes", 'y' "true", "t", "1"]:
- return True
- if v in ["no", 'n' "false", "f", "0", '', 'null', 'none']:
- return False
- raise ValueError('Can not convert `' + v + '` to bool')
- def my_tabulate(data, **params):
- if data == [] and 'headers' in params:
- data = [(None for _ in params['headers'])]
- tabulate.MIN_PADDING = 0
- return tabulate.tabulate(data, **params)
- def yn_dialog(msg):
- while True:
- result = input(msg + ' [y/n]: ')
- if result == 'y':
- return True
- if result == 'n':
- return False
- print('Type in \'y\' or \'n\'!')
|