Skip to content

Instantly share code, notes, and snippets.

@ObjectBoxPC
Created July 24, 2023 16:23
Show Gist options
  • Save ObjectBoxPC/16a32f6ae31fcc0de7d5df52e7618faf to your computer and use it in GitHub Desktop.
Save ObjectBoxPC/16a32f6ae31fcc0de7d5df52e7618faf to your computer and use it in GitHub Desktop.
Quickly generate random numeric PINs
#!/usr/bin/env python3
# Usage: ./makepin.py [number of digits, default 4]
import secrets
import sys
if len(sys.argv) < 2:
digit_count = 4
else:
digit_count = int(sys.argv[1])
pin = secrets.randbelow(10**digit_count)
pin_format = "{{:0{}}}".format(digit_count)
print(pin_format.format(pin))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment