Skip to content

Instantly share code, notes, and snippets.

@ObjectBoxPC
Last active June 3, 2024 22:13
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
digit_count = int(sys.argv[1]) if len(sys.argv) >= 2 else 4
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