-
-
Save joshkunz/790bda7a46794306405e to your computer and use it in GitHub Desktop.
Code to generate a map between pairs of pre-2011 SSNs.
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
import random | |
import sys | |
L_AREA = 649 | |
H_AREA_LOW = 700 | |
H_AREA = 29 | |
A_SIZE = L_AREA + H_AREA | |
G_SIZE = 99 | |
S_SIZE = 9999 | |
T_SIZE = A_SIZE * G_SIZE * S_SIZE | |
def rand_area(): | |
cat = random.random() | |
if cat < (float(L_AREA) / A_SIZE): | |
return random.randint(1, L_AREA) | |
else: | |
return random.randint(H_AREA_LOW, H_AREA_LOW + H_AREA) | |
def rand_ssn(): | |
area = rand_area() | |
group = random.randint(1, G_SIZE) | |
serial = random.randint(1, S_SIZE) | |
return (area, group, serial) | |
def rand_map(size): | |
for _ in xrange(size): | |
yield rand_ssn(), rand_ssn() | |
first_ssn = (1, 1, 1) | |
def inc_ssn((area, group, serial)): | |
serial = (serial + 1) % (S_SIZE + 1) | |
if serial == 0: | |
serial += 1 | |
group = (group + 1) % (G_SIZE + 1) | |
if group == 0: | |
group += 1 | |
area = (area + 1) | |
if H_AREA_LOW > area > L_AREA: | |
area = H_AREA_LOW | |
elif area == (H_AREA_LOW + H_AREA + 1): | |
raise StopIteration() | |
return (area, group, serial) | |
def iter_ssn(from_=first_ssn): | |
yield from_ | |
ssn = from_ | |
while True: | |
ssn = inc_ssn(ssn) | |
yield ssn | |
def rand_unique_map(): | |
for ssn in iter_ssn(): | |
yield ssn, rand_ssn() | |
def does_rand_collide(map): | |
for i, (a, b) in enumerate(map): | |
sys.stdout.write("Testing: %s\r" % i) | |
sys.stdout.flush() | |
if a == b: return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment