def division_hash(k,r): return k%r def multiplication_hash(k,r): A = (5**.5-1)/2 # arbitrary number (0,1) M = (A*k)%1 return int(M*r) def test_hash(hash_func,r,tests): results = [0]*r for k in range(tests): results[hash_func(k,r)]+=1 return results print(test_hash(multiplication_hash,100,1000000))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question