Generators
generate_random_id¶
Generates a random alphanumeric string (ASCII letters and digits) of the given length. Defaults to 7 characters.
| Parameter | Type | Default | Description |
|---|---|---|---|
chars |
int |
7 |
Length of the generated id |
Note
Characters are drawn with secrets.choice, so the output cannot be predicted from earlier ids. The default length of 7 is still short (about 41 bits): fine for readable ids, too small for a token or invite code. For those, pass a longer chars (22 or more) or use secrets.token_urlsafe().