Created
March 16, 2012 08:50
-
-
Save verm666/2049204 to your computer and use it in GitHub Desktop.
djb2.py
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
#!/usr/bin/env | |
# -*- coding: utf-8 -*- | |
from pprint import pprint | |
def djb2(uuid): | |
""" See for details: http://www.cse.yorku.ca/~oz/hash.html """ | |
_hash = 5381 | |
for i in xrange(0, len(uuid)): | |
_hash = ((_hash << 5) + _hash) + ord(uuid[i]) | |
return _hash | |
if __name__ == "__main__": | |
import uuid | |
result = {} | |
for i in xrange(10000): | |
_uuid = str(uuid.uuid1()) | |
_id = djb2(_uuid) % 16 | |
try: | |
result[int(_id)] += 1 | |
except KeyError: | |
result[int(_id)] = 1 | |
pprint(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment