Skip to content

Instantly share code, notes, and snippets.

@WillKoehrsen
Last active September 26, 2018 16:33
Show Gist options
  • Save WillKoehrsen/90fa42e49648624b36fbedd5eb36a27a to your computer and use it in GitHub Desktop.
Save WillKoehrsen/90fa42e49648624b36fbedd5eb36a27a to your computer and use it in GitHub Desktop.
import hashlib
N_PARTITIONS = 1000
def id_to_hash(customer_id):
"""Return a 16-bit integer hash of a customer id string"""
customer_hash = int(hashlib.md5(customer_id).hexdigest(), 16)
partition = customer_hash % N_PARTITIONS
return partition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment