Skip to content

Commit 7e57e19

Browse files
committed
mgssalim|string_generator|Changes
1 parent 95a2f88 commit 7e57e19

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

string_generator/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# String Generator
2+
3+
This is a simple string generator on Python to generate a random string, this logic could help you to generate new random string, useful for creating new unique code for your database, which can be a combination of:
4+
- lowercase charaters
5+
- uppercase characters
6+
- digits
7+
8+
To run the program, simply type the following in the terminal:
9+
10+
```python main.py```

string_generator/main.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import string,random
2+
3+
def string_generator(size, chars):
4+
return ''.join(random.choice(chars) for _ in range(size))
5+
6+
7+
def get_option(option):
8+
if option == 'alphabet':
9+
characters = string.ascii_uppercase + string.ascii_lowercase + string.digits
10+
elif option == 'numeric':
11+
characters = string.digits
12+
else:
13+
print('option out of context!')
14+
15+
return characters
16+
17+
# choose want alphabet generic or numeric generic
18+
option = 'alphabet'
19+
# choose length of size string
20+
size = 10
21+
22+
characters = get_option(option)
23+
24+
new_number = string_generator(size,characters)
25+
print(new_number)

0 commit comments

Comments
 (0)