forked from Show-Me-the-Code/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
22 lines (19 loc) · 655 Bytes
/
main.py
File metadata and controls
22 lines (19 loc) · 655 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'jinyang'
from random import Random
def codeGenerator(number, codeLength = 8):
print '**** Code Generator ****'
codeFile = open('codes.txt', 'w')
if number <= 0:
return 'invalid number of codes'
else:
chars = 'abcdefghijklmnopgrstuvwxyzABCDEFGHIJKLMNOPGRSTUVWXYZ1234567890'
random = Random()
for j in range(1, number+1):
str = ''
for i in range(1, codeLength+1):
index = random.randint(1, len(chars))
str = str + chars[index-1]
codeFile.write(str+'\n')
print codeGenerator(200)