Skip to content

Instantly share code, notes, and snippets.

@anderseknert
Last active September 18, 2019 07:03
Show Gist options
  • Save anderseknert/b3823d152928f1c1d6cf8173a238567c to your computer and use it in GitHub Desktop.
Save anderseknert/b3823d152928f1c1d6cf8173a238567c to your computer and use it in GitHub Desktop.
Generate random swedish personal ID
import datetime, random
ssid = "{}{:02d}{}".format(*[x for x in ['{:%y%m%d}'.format(datetime.datetime(1970, 1, 1) + datetime.timedelta(days=random.randint(-30, 30) * 365 + random.randint(0, 365))), random.randint(0, 99), random.randint(0, 9)]])
print("{}{}".format(ssid, (10 - (sum(map(lambda x: x%10 + int(x/10), map(lambda x,y: x*y, map(int, ssid), [2,1]*4 + [2]))) % 10)) % 10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment