Generate Random String

Generate a cryptographically secure random string of specified length using the Web Crypto API.

Code

Utilities
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const randomValues = new Uint32Array(length);
crypto.getRandomValues(randomValues);
return Array.from(randomValues, v => chars[v % chars.length]).join('');

Parameters

Length of the random string to generate.

Browser·fetch() may be limited by CORS

More JavaScript Snippets