Skip to content

Instantly share code, notes, and snippets.

@mmkhitaryan
Created December 12, 2020 13:23
Show Gist options
  • Select an option

  • Save mmkhitaryan/d6deed33f9fbda8d2cfffae538a74522 to your computer and use it in GitHub Desktop.

Select an option

Save mmkhitaryan/d6deed33f9fbda8d2cfffae538a74522 to your computer and use it in GitHub Desktop.
Алгоритм для равномерного распределения массивов
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