Skip to content

TypeScript API / laikacms/crypto / generateSecureRandomString

Function: generateSecureRandomString() ​

ts
function generateSecureRandomString(length, alphabet?): string;

Generate cryptographically secure random strings using rejection sampling. This eliminates modulo bias which could theoretically be exploited by quantum computers with sufficient qubits.

Uses base62 alphabet (A-Za-z0-9) for URL-safe tokens by default.

Parameters ​

ParameterTypeDefault valueDescription
lengthnumberundefinedDesired length of the output string
alphabetstringRANDOM_CONSTANTS.BASE62_ALPHABETCharacter set to use (default: base62)

Returns ​

string

Cryptographically secure random string

Released under the MIT License.