Skip to content

Instantly share code, notes, and snippets.

@voroninman
Created September 10, 2017 09:38
Show Gist options
  • Save voroninman/aedb4e162ec35d79bb775103fc720ef9 to your computer and use it in GitHub Desktop.
Save voroninman/aedb4e162ec35d79bb775103fc720ef9 to your computer and use it in GitHub Desktop.
from hashlib import md5
from collections import Counter
BETA_ROLL_OUT_PERSANTAGE = 10
def hash_func(key):
return sum(map(ord, md5(key).hexdigest()))
def is_beta_enabled(user_id):
key = "{}|beta".format(user_id)
user_percentage = hash_func(key) % 100
return user_percentage > 100 - BETA_ROLL_OUT_PERSANTAGE
print(is_beta_enabled(94399))
# False
print(Counter([is_beta_enabled(user_id) for user_id in range(100)]))
# Counter({False: 92, True: 8})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment