Settings for common uses
| Use | Suggested setup |
|---|---|
| API key or secret token | 32–64 characters, letters + numbers |
| Session or CSRF token | 32+ characters, letters + numbers |
| Coupon or invite code | 8–12 characters, uppercase + numbers, exclude similar |
| Test data / unique slugs | 8–16 characters, lowercase + numbers |
A 32-character alphanumeric string has about 191 bits of entropy — far more than the 128 bits usually recommended for secrets.
Is it really random?
Yes. Characters are drawn with crypto.getRandomValues, the browser's cryptographically secure generator, using rejection sampling so every character is equally likely. Nothing is sent to a server. Math.random(), by contrast, is not suitable for secrets.
In code
- Python:
secrets.token_urlsafe(32) - Node.js:
crypto.randomBytes(24).toString('base64url') - OpenSSL:
openssl rand -hex 32


