Skip to content

Instantly share code, notes, and snippets.

@methane
Created June 29, 2012 05:35
Show Gist options
  • Select an option

  • Save methane/3016017 to your computer and use it in GitHub Desktop.

Select an option

Save methane/3016017 to your computer and use it in GitHub Desktop.
シリアルコード発行用スクリプト
#!/usr/bin/env python
import random
import sys
from glob import glob
import os
BASE = os.path.dirname(__file__)
CHARS = 'ABCDEFGHJKMNPQRSTUVWXYZ23456789'
N = int(sys.argv[1])
M = int(sys.argv[2])
used = set()
for fn in glob(BASE + '/code/*.txt'):
with open(fn) as f:
for code in f:
used.add(code.strip())
m = 0
while m < M:
c = ''.join([random.choice(CHARS) for _ in xrange(N)])
if c not in used:
m += 1
used.add(c)
print c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment