Created
December 12, 2020 13:23
-
-
Save mmkhitaryan/d6deed33f9fbda8d2cfffae538a74522 to your computer and use it in GitHub Desktop.
Алгоритм для равномерного распределения массивов
This file contains hidden or 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 hashlib | |
| import random | |
| import collections | |
| def random_string(N): | |
| import string | |
| return ''.join(random.choices(string.ascii_uppercase + string.digits, k=N)) | |
| def md5(string): | |
| hash = hashlib.md5(string.encode('utf-8')) | |
| return int.from_bytes(hash.digest()[0:2], "little") | |
| def partition_for(n): | |
| counter = collections.Counter() | |
| list_of_hashed_random_strings = [md5(random_string(5)) for x in range(900)] | |
| for element in list_of_hashed_random_strings: | |
| counter.update(str(element % n)) | |
| return counter | |
| part = partition_for(9) | |
| breakpoint() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment