Generate a prefixed task id of the form `` <8 base36 chars>``. ``secrets.choice`` (CSPRNG) — NOT ``random.choice`` — to mirror TS's ``crypto.randomInt`` at ``typescript/src/Task.ts:102``. The chapter explains the rationale: 36^8 combinations resists brute-forcing of task outp
(task_type: TaskType)
| 83 | |
| 84 | |
| 85 | def generate_task_id(task_type: TaskType) -> str: |
| 86 | """Generate a prefixed task id of the form ``<prefix><8 base36 chars>``. |
| 87 | |
| 88 | ``secrets.choice`` (CSPRNG) — NOT ``random.choice`` — to mirror TS's |
| 89 | ``crypto.randomInt`` at ``typescript/src/Task.ts:102``. The chapter |
| 90 | explains the rationale: 36^8 combinations resists brute-forcing of task |
| 91 | output filenames written under predictable paths. ``random.choice`` is |
| 92 | seeded from process state and would weaken that guarantee. |
| 93 | """ |
| 94 | prefix = _TASK_ID_PREFIXES.get(task_type, "x") |
| 95 | body = "".join(secrets.choice(_TASK_ID_ALPHABET) for _ in range(_TASK_ID_BODY_LEN)) |
| 96 | return prefix + body |
| 97 | |
| 98 | |
| 99 | # --------------------------------------------------------------------------- |