Created
May 12, 2015 21:27
-
-
Save yankov/f81dabdf6f4098100078 to your computer and use it in GitHub Desktop.
hash tests
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
%matplotlib inline | |
import md5, struct | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
import mmh3 | |
def md5hash(i): | |
return md5.new(str(i)).digest()[12:16] | |
def mm(i): | |
return mmh3.hash(str(i), seed = 1234 ) | |
f, axes = plt.subplots(2, 1, figsize=(7, 7), sharex=True) | |
n = 42 | |
z = 100000 | |
nums = [struct.unpack("<i", md5hash(i))[0] % n for i in range(0,z)] | |
#sns.distplot(nums, kde=False, ax=axes[0]) | |
nums_m = [mm(i) % n for i in range(0,z)] | |
#sns.distplot(nums_m, kde=False, ax=axes[1]) | |
pd.Series(nums).hist(ax=axes[0]) | |
pd.Series(nums_m).hist(ax=axes[1]) | |
#plt.setp(axes, yticks=[]) | |
#plt.tight_layout() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The same test in Scala: