Created
September 10, 2017 09:38
-
-
Save voroninman/aedb4e162ec35d79bb775103fc720ef9 to your computer and use it in GitHub Desktop.
This file contains 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
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