Last active
January 12, 2022 18:29
-
-
Save timgl/4ea5f1dad8d3b4329be77561beb7e49f 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
__LONG_SCALE__ = float(0xFFFFFFFFFFFFFFF) | |
import hashlib | |
import secrets | |
def hash(identifier): | |
hash_key = f"test.{identifier}.{secrets.token_hex(32)}" | |
hash_val = int(hashlib.sha1(hash_key.encode("utf-8")).hexdigest()[:15], 16) | |
return hash_val / __LONG_SCALE__ | |
trues = 1 | |
falses = 1 | |
for i in range(0, 10000): | |
if hash(i) > 0.5: | |
falses += 1 | |
else: | |
trues += 1 | |
if i % 500 == 0: | |
print(f"Index: {i} true: {trues} false: {falses} diff: {((trues-falses)/falses)*100}%") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment