Skip to content

Instantly share code, notes, and snippets.

@verm666
Created March 16, 2012 08:50
Show Gist options
  • Save verm666/2049204 to your computer and use it in GitHub Desktop.
Save verm666/2049204 to your computer and use it in GitHub Desktop.
djb2.py
#!/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