Created
March 14, 2017 14:32
-
-
Save subuk/75f14a0327f63f796af3f4799e16dee0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import random | |
import hashlib | |
_generated = set() | |
def rand_ip_part(): | |
return random.randint(0, 255) | |
def gen_ip(): | |
r = rand_ip_part | |
return "%d.%d.%d.%d" % (r(), r(), r(), r()) | |
def gen_uniq_ip(): | |
global _generated | |
while True: | |
ip = gen_ip() | |
if ip not in _generated: | |
_generated.add(ip) | |
return ip | |
def should_redirect(ip): | |
return int(hashlib.sha256(ip).hexdigest(), 16) % 100 >= 5 | |
def main(): | |
yes = 0 | |
no = 0 | |
for x in xrange(0, 10000, 1): | |
if should_redirect(gen_uniq_ip()): | |
yes += 1 | |
else: | |
no += 1 | |
print "YES:", yes, "NO:", no | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment