SHARE
TWEET

Untitled

a guest Dec 13th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. import random
  3.  
  4. def get_tenant_id(namespace: str) -> int:
  5.   return hash(namespace) % ((sys.maxsize + 1) * 2)
  6.  
  7. namespace = 'my_namespace'
  8.  
  9. def expect_not_same_hash():
  10.   hashes = {}
  11.   hashes[get_tenant_id(namespace)] = namespace
  12.  
  13.   # obviously a python 3 file!!!
  14.   for i in range(1000000000):
  15.     new_namespace = (
  16.       [number for number in str(random.randint(0, sys.maxsize))] + [letter for letter in namespace]
  17.     )
  18.  
  19.     random.shuffle(new_namespace)
  20.     new_namespace = ''.join(new_namespace)
  21.  
  22.     new_namespace_hash = get_tenant_id(new_namespace)
  23.  
  24.     print(i, new_namespace)
  25.  
  26.     assert hashes.get(new_namespace_hash) == None
  27.     hashes[new_namespace_hash] = new_namespace
  28.  
  29. expect_not_same_hash()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top