Skip to content

Commit 8dd8a70

Browse files
authored
Create random-names.py
1 parent 05ec4f4 commit 8dd8a70

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

Diff for: random-names.py

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#! python3
2+
# -*- coding: utf-8 -*-
3+
import random
4+
import string
5+
6+
FirstNames = './Names/FirstNames.txt'
7+
MiddleNames = './Names/MiddleNames.txt'
8+
LastNames = './Names/LastNames.txt'
9+
CountyNames = './Names/CountyNames.txt'
10+
PlaceNames = './Names/PlaceNames.txt'
11+
StateNames = './Names/StateNames.txt'
12+
CountryNames = './Names/CountryNames.txt'
13+
CompanyNames = './Names/CompanyNames.txt'
14+
15+
16+
17+
def Number(start=0, end=100000):
18+
'''
19+
Returns random integer between range of numbers
20+
'''
21+
return random.randint(start, end)
22+
23+
24+
def UpperChars(NoOfChars=2):
25+
'''
26+
UpperChars(NoOfChars=2) Returns 2 random CAPITAL letters.
27+
'''
28+
_char = ''
29+
for num in range(NoOfChars):
30+
_char += random.choice(string.ascii_uppercase)
31+
return _char
32+
33+
34+
def rawCount(filename):
35+
"""
36+
Function to get Line Count in txt files.
37+
rawcount('C:\A.txt') outputs integer value of count of lines.
38+
"""
39+
with open(filename, 'rb') as f:
40+
lines = 1
41+
buf_size = 1024 * 1024
42+
read_f = f.raw.read
43+
44+
buf = read_f(buf_size)
45+
while buf:
46+
lines += buf.count(b'\n')
47+
buf = read_f(buf_size)
48+
return lines
49+
50+
51+
def randomLine(filename):
52+
num = int(random.uniform(0, rawCount(filename)))
53+
with open(filename, 'r') as f:
54+
for i, line in enumerate(f, 1):
55+
if i == num:
56+
break
57+
return line.strip('\n')
58+
59+
60+
def First():
61+
return randomLine(FirstNames)
62+
63+
64+
def Last():
65+
return randomLine(LastNames)
66+
67+
68+
def Middle():
69+
return randomLine(MiddleNames)
70+
71+
72+
def States():
73+
return randomLine(StateNames)
74+
75+
76+
def Places():
77+
return randomLine(PlaceNames)
78+
79+
80+
def County():
81+
return randomLine(CountyNames)
82+
83+
84+
def Company():
85+
return randomLine(CompanyNames)
86+
87+
88+
def Country():
89+
_Cc = randomLine(CountryNames)
90+
_Cc = _Cc.split('|')
91+
return _Cc[1]
92+
93+
94+
def CountryCode():
95+
_Cc = randomLine(CountryNames)
96+
_Cc = _Cc.split('|')
97+
return _Cc[0]
98+
99+
100+
def StateCode():
101+
return States().split(', ')[1]
102+
103+
104+
def Full():
105+
'''
106+
Returns a random First Name and Last Name combination
107+
'''
108+
return ' '.join([First(), Last()])
109+
110+
111+
def Address():
112+
"""
113+
Returns a Random address in the Format:
114+
54F - Sauk, Middle, New Mexico, NM, 4292.
115+
"""
116+
_door = str(Number(11, 99))
117+
_zip = str(Number(1000, 9999))
118+
_adrs = ', '.join([Places(), County(), States(), _zip])
119+
_adrs = _door + UpperChars(1) + ' - ' + _adrs + '.'
120+
return _adrs
121+
122+
123+
def ShortAddress():
124+
"""
125+
Returns a Short Random address in the Format:
126+
31 Outagamie, Wisconsin, WI, 8281
127+
"""
128+
_door = str(Number(11, 99))
129+
_zip = str(Number(1000, 9999))
130+
_adrs = ', '.join([County(), States(), _zip])
131+
_adrs = _door + ' ' + _adrs
132+
return _adrs
133+
134+
135+
if __name__ == '__main__':
136+
print(Full(), ' works at ', Company(), ' lives at ', Address(), StateCode(), Country())

0 commit comments

Comments
 (0)