-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrandom_string.py
More file actions
executable file
·48 lines (35 loc) · 1.08 KB
/
random_string.py
File metadata and controls
executable file
·48 lines (35 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /usr/bin/env python
#coding:utf8
"""
Author: tao peng --<taopeng@meilishuo.com>
Purpose:
1. 生成随机字符串
History:
1. 2014/6/17 11:10 : random_string.py is created.
"""
import sys
import random
from argparse import ArgumentParser
#----------------------------------------------------------------------
def parse_args():
"""
"""
parser = ArgumentParser(description='generate random string.')
parser.add_argument("length", metavar='LENGTH', type=int, help="the length of random string.")
parser.add_argument("--num", metavar='NUM', type=int, default=1, help="number of required strings.")
args = parser.parse_args()
return args
#----------------------------------------------------------------------
def main(args):
""" """
table = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(args.num):
j = 0
s = ''
while j < args.length:
s += table[random.randint(0,61)]
j += 1
print s
if __name__=='__main__':
args = parse_args()
main(args)