Skip to content

Commit a5e362c

Browse files
committed
updated
1 parent c02537f commit a5e362c

File tree

5 files changed

+59
-59
lines changed

5 files changed

+59
-59
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# random-string
1+
# rand-string
22
Generates a random string of a specified length.
33

44
# Usage
@@ -13,36 +13,37 @@ You can probably guess what each one would create
1313

1414
The function requires 2 parameters type and length; Type of course is the above.
1515
```py
16-
RandString(type, length)
16+
import rand_string.rand_string as rand
17+
rand.RandString(type, length)
1718
```
1819
Now lets look at some examples
1920

2021
uppercase:
2122
```py
22-
print(RandString("uppercase", 10))
23+
print(rand.RandString("uppercase", 10))
2324
# Output: TPDROEAVRY
2425
```
2526

2627
lowercase:
2728
```py
28-
print(RandString("lowercase", 10))
29+
print(rand.RandString("lowercase", 10))
2930
# Output: mdvsewzkwf
3031
```
3132

3233
upperlower:
3334
```py
34-
print(RandString("upperlower", 10))
35+
print(rand.RandString("upperlower", 10))
3536
# Output: YjHFGzysFx
3637
```
3738

3839
alphanumerical:
3940
```py
40-
print(RandString("alphanumerical", 10))
41+
print(rand.RandString("alphanumerical", 10))
4142
# Output: Fy0Nbqno6B
4243
```
4344

4445
ascii:
4546
```py
46-
print(RandString("ascii", 10))
47+
print(rand.RandString("ascii", 10))
4748
# Output: jtj-NV<PSV
4849
```

rand-string/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

rand_string/__init__.py

Whitespace-only changes.
Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
import random as rand
2-
3-
def RandString(type, length):
4-
length = int(length)
5-
if length <= 0: raise Exception("Invalid length in RandString({}, {})".format(type, length))
6-
if type == "uppercase":
7-
response = ""
8-
for i in range(length):
9-
code = rand.randint(65, 90)
10-
response += chr(code)
11-
return response
12-
elif type == "lowercase":
13-
response = ""
14-
for i in range(length):
15-
code = rand.randint(97, 122)
16-
response += chr(code)
17-
return response
18-
elif type == "upperlower":
19-
response = ""
20-
choices = ["upper", "lower"]
21-
code = 0
22-
for i in range(length):
23-
choice = rand.choice(choices)
24-
if choice == "upper": code = rand.randint(65, 90)
25-
else: code = rand.randint(97, 122)
26-
response += chr(code)
27-
return response
28-
elif type == "alphanumerical":
29-
response = ""
30-
choices = ["upper", "lower", "number"]
31-
code = 0
32-
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)
36-
else: code = rand.randint(48, 57)
37-
response += chr(code)
38-
return response
39-
elif type == "ascii":
40-
response = ""
41-
choice = 0
42-
code = 0
43-
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)
47-
response += chr(code)
48-
return response
49-
else: raise Exception("Invalid type in RandString({}, {})".format(type, length))
1+
import random as rand
2+
3+
def RandString(type, length):
4+
length = int(length)
5+
if length <= 0: raise Exception("Invalid length in RandString({}, {})".format(type, length))
6+
if type == "uppercase":
7+
response = ""
8+
for i in range(length):
9+
code = rand.randint(65, 90)
10+
response += chr(code)
11+
return response
12+
elif type == "lowercase":
13+
response = ""
14+
for i in range(length):
15+
code = rand.randint(97, 122)
16+
response += chr(code)
17+
return response
18+
elif type == "upperlower":
19+
response = ""
20+
choices = ["upper", "lower"]
21+
code = 0
22+
for i in range(length):
23+
choice = rand.choice(choices)
24+
if choice == "upper": code = rand.randint(65, 90)
25+
else: code = rand.randint(97, 122)
26+
response += chr(code)
27+
return response
28+
elif type == "alphanumerical":
29+
response = ""
30+
choices = ["upper", "lower", "number"]
31+
code = 0
32+
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)
36+
else: code = rand.randint(48, 57)
37+
response += chr(code)
38+
return response
39+
elif type == "ascii":
40+
response = ""
41+
choice = 0
42+
code = 0
43+
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)
47+
response += chr(code)
48+
return response
49+
else: raise Exception("Invalid type in RandString({}, {})".format(type, length))

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
setup(
77
name = "rand-string",
8-
packages = ["rand-string"],
9-
version = "0.3",
8+
packages = ["rand_string"],
9+
version = "0.40",
1010
license="MIT",
1111
description = "Generates a random string of a specified length.",
1212
long_description=readme,

0 commit comments

Comments
 (0)