forked from SamuraJey/HACK
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_string_22.py
More file actions
38 lines (29 loc) · 1.08 KB
/
generate_string_22.py
File metadata and controls
38 lines (29 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import random
import string
def generate_random_string(length=22):
"""Generates a random string of specified length.
Args:
length: The desired length of the string (default is 22).
Returns:
A random string of the specified length, or None if an error occurs.
"""
try:
# Define the character set
characters = string.ascii_lowercase + \
string.ascii_uppercase + "$_" + string.digits
# Check if the length is valid. A negative length is not allowed.
if length < 0:
print("Error: Length must be a non-negative integer.")
return None
# Generate the random string
random_string = ''.join(random.choice(characters)
for i in range(length))
return random_string
except Exception as e:
print(f"An error occurred: {e}")
return None
# Get a 22-character random string
with open(f'random_strings.txt', 'w') as file:
for i in range(10):
random_string = generate_random_string()
file.write(random_string + '\n')