Generate a random string of fixed length. Args: length: Length of the generated string. alphabet: Optional character set to draw from. If None, uses [A-Za-z0-9].
(length: int, *, alphabet: Optional[str] = None)
| 8 | |
| 9 | |
| 10 | def random_string(length: int, *, alphabet: Optional[str] = None) -> str: |
| 11 | """ |
| 12 | Generate a random string of fixed length. |
| 13 | |
| 14 | Args: |
| 15 | length: Length of the generated string. |
| 16 | alphabet: Optional character set to draw from. If None, uses [A-Za-z0-9]. |
| 17 | """ |
| 18 | if length < 0: |
| 19 | raise ValueError("String length cannot be negative.") |
| 20 | |
| 21 | alphabet = alphabet or (string.ascii_letters + string.digits) |
| 22 | return "".join(random.choices(alphabet, k=length)) |
| 23 | |
| 24 | |
| 25 | def _resolve_param(value: Union[int, Tuple[int, int]], name: str) -> int: |
no outgoing calls
no test coverage detected