Skip to content

Instantly share code, notes, and snippets.

@typosone
Created July 29, 2014 17:47
Show Gist options
  • Save typosone/284079cb898b0ee07148 to your computer and use it in GitHub Desktop.
Save typosone/284079cb898b0ee07148 to your computer and use it in GitHub Desktop.
Python3 でランダム文字列作るやつ。
#!/usr/bin/env python3
import sys
import random
argv = sys.argv
argc = len(argv)
if argc not in {2, 3}:
print("Usage: pass_gen digis [mode(1:number,2:lower,4:upper,8:specials]")
quit()
if argc == 3:
mode = int(argv[2])
else:
mode = 1
length = int(argv[1])
seed = ""
if mode & 0x01 == 1:
seed += "0123456789"
if mode >> 1 & 0x01 == 1:
seed += "abcdefghijklmnopqrstuvwxyz"
if mode >> 2 & 0x01 == 1:
seed += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
if mode >> 3 & 0x01 == 1:
seed += "!@#$%^&*()_[];:,./<>"
print("".join([random.choice(seed) for x in range(length)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment