Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement