-
Notifications
You must be signed in to change notification settings - Fork 0
/
alphanumericCombination.py
61 lines (51 loc) · 1.38 KB
/
alphanumericCombination.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: UTF-8 -*-
'''
@author: mengting gu
@contact: [email protected]
@time: 2020/11/3 下午9:04
@file: random_num.py
@desc:
Get the combination of n numbers and upper and lower case letters.
'''
import random
n = 6
def v_code_nums_letters(n=6):
"""
Returns:
ret:random six num and letter
"""
ret = ""
for i in range(n):
num = random.randint(0, 9)
# num = chr(random.randint(48,57))#ASCII表示数字
letter = chr(random.randint(97, 122)) # 取小写字母
Letter = chr(random.randint(65, 90)) # 取大写字母
s = str(random.choice([num, letter, Letter]))
ret += s
return ret
def v_code_letters(n=6):
"""
Returns:
ret:random six letter
"""
ret = ""
for i in range(n):
letter = chr(random.randint(97, 122)) # 取小写字母
Letter = chr(random.randint(65, 90)) # 取大写字母
s = str(random.choice([letter, Letter]))
ret += s
return ret
def v_code_nums(n=6):
"""
Returns:
ret:random six num
"""
ret = ""
for i in range(n):
num = random.randint(0, 9)
s = str(random.choice([num]))
ret += s
return ret
print("v_code_nums_letters result: " + v_code_nums_letters())
print("v_code_letters result: " + v_code_letters())
print("v_code_nums result: " + v_code_nums())