mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-27 14:01:15 +00:00
random string generator
This commit is contained in:
parent
2f3ae7cad7
commit
c76d80a540
|
@ -97,6 +97,9 @@ GitHub repository [One-Python-benchmark-per-day](https://github.com/rasbt/One-Py
|
||||||
|
|
||||||
- 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)]
|
- 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)]
|
||||||
|
|
||||||
|
- A random string generator [function](./useful_scripts/random_string_generator.py)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
|
19
useful_scripts/random_string_generator.py
Normal file
19
useful_scripts/random_string_generator.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import string
|
||||||
|
import random
|
||||||
|
|
||||||
|
def rand_string(length):
|
||||||
|
""" Generates a random string of numbers, lower- and uppercase chars. """
|
||||||
|
return ''.join(random.choice(
|
||||||
|
string.ascii_lowercase + string.ascii_uppercase + string.digits)
|
||||||
|
for i in range(length)
|
||||||
|
)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print("Example1:", rand_string(length=4))
|
||||||
|
print("Example2:", rand_string(length=8))
|
||||||
|
print("Example2:", rand_string(length=16))
|
||||||
|
|
||||||
|
|
||||||
|
# Example1: 5bVL
|
||||||
|
# Example2: oIIg37xl
|
||||||
|
# Example2: 7IqDbrf506TatFO9
|
Loading…
Reference in New Issue
Block a user