26 lines
567 B
Python
26 lines
567 B
Python
import random
|
|
import string
|
|
from typing import Optional
|
|
|
|
|
|
def random_string(
|
|
length: Optional[int] = None,
|
|
prefix: Optional[str] = None,
|
|
suffix: Optional[str] = None,
|
|
) -> str:
|
|
if length is None:
|
|
length = 10
|
|
random_str = ''.join(
|
|
random.choice(string.ascii_letters + string.digits)
|
|
for _ in range(length)
|
|
)
|
|
return (
|
|
f'{"" if prefix is None else prefix}'
|
|
f'{random_str}'
|
|
f'{"" if suffix is None else suffix}'
|
|
)
|
|
|
|
|
|
def random_email() -> str:
|
|
return random_string(suffix='@example.com')
|