-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_string.py
31 lines (27 loc) · 1.21 KB
/
random_string.py
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
from snowfakery import SnowfakeryPlugin
from string import ascii_lowercase, ascii_uppercase, digits
from random import choice, randrange
class RandomString(SnowfakeryPlugin):
class Functions:
def random_string(self, length: int, fixed: bool, case: str) -> str:
if fixed:
max_length = length
else:
max_length = randrange(length)
match case.upper():
case 'UPPER':
randomString = ''.join(
[choice(ascii_uppercase) for i in range(max_length)])
case 'LOWER':
randomString = ''.join(
[choice(ascii_lowercase) for i in range(max_length)])
case 'NUMBERS':
randomString = ''.join(
[choice(digits) for i in range(max_length)])
case 'CAPITALISE':
randomString = ''.join(
[choice(ascii_lowercase) for i in range(max_length)]).capitalize()
case _:
randomString = ''.join(
[choice(ascii_lowercase) for i in range(max_length)]).capitalize()
return randomString