Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c76d80a

Browse files
committed
random string generator
1 parent 2f3ae7c commit c76d80a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ GitHub repository [One-Python-benchmark-per-day](https://github.com/rasbt/One-Py
9797

9898
- convert 'tab-delimited' to 'comma-separated' CSV files [[IPython nb](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/useful_scripts/fix_tab_csv.ipynb?create=1)]
9999

100+
- A random string generator [function](./useful_scripts/random_string_generator.py)
101+
102+
100103

101104
<br>
102105

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import string
2+
import random
3+
4+
def rand_string(length):
5+
""" Generates a random string of numbers, lower- and uppercase chars. """
6+
return ''.join(random.choice(
7+
string.ascii_lowercase + string.ascii_uppercase + string.digits)
8+
for i in range(length)
9+
)
10+
11+
if __name__ == '__main__':
12+
print("Example1:", rand_string(length=4))
13+
print("Example2:", rand_string(length=8))
14+
print("Example2:", rand_string(length=16))
15+
16+
17+
# Example1: 5bVL
18+
# Example2: oIIg37xl
19+
# Example2: 7IqDbrf506TatFO9

0 commit comments

Comments
 (0)