Skip to content

Commit 314695b

Browse files
committed
misc changes
changed the choice to an integer
1 parent a5e362c commit 314695b

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

rand_string/rand_string.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,39 @@ def RandString(type, length):
99
code = rand.randint(65, 90)
1010
response += chr(code)
1111
return response
12+
1213
elif type == "lowercase":
1314
response = ""
1415
for i in range(length):
1516
code = rand.randint(97, 122)
1617
response += chr(code)
1718
return response
19+
1820
elif type == "upperlower":
1921
response = ""
20-
choices = ["upper", "lower"]
2122
code = 0
2223
for i in range(length):
23-
choice = rand.choice(choices)
24-
if choice == "upper": code = rand.randint(65, 90)
24+
choice = rand.randint(0, 1)
25+
if choice == 0: code = rand.randint(65, 90)
2526
else: code = rand.randint(97, 122)
2627
response += chr(code)
2728
return response
29+
2830
elif type == "alphanumerical":
2931
response = ""
30-
choices = ["upper", "lower", "number"]
3132
code = 0
3233
for i in range(length):
33-
choice = rand.choice(choices)
34-
if choice == "upper": code = rand.randint(65, 90)
35-
elif choice == "lower": code = rand.randint(97, 122)
34+
choice = rand.randint(0, 2)
35+
if choice == 0: code = rand.randint(65, 90)
36+
elif choice == 1: code = rand.randint(97, 122)
3637
else: code = rand.randint(48, 57)
3738
response += chr(code)
3839
return response
40+
3941
elif type == "ascii":
4042
response = ""
41-
choice = 0
42-
code = 0
4343
for i in range(length):
44-
choice = rand.randint(0, 1)
45-
if choice == 0: code = rand.randint(33, 95)
46-
else: code = rand.randint(97, 125)
44+
code = rand.randint(33, 126)
4745
response += chr(code)
4846
return response
4947
else: raise Exception("Invalid type in RandString({}, {})".format(type, length))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
setup(
77
name = "rand-string",
88
packages = ["rand_string"],
9-
version = "0.40",
9+
version = "0.5",
1010
license="MIT",
1111
description = "Generates a random string of a specified length.",
1212
long_description=readme,

0 commit comments

Comments
 (0)