Skip to content

Instantly share code, notes, and snippets.

@nanderLP
Last active October 2, 2022 13:45
Show Gist options
  • Save nanderLP/a96a5b0c4a0e9177ee06cbc0e048fb9b to your computer and use it in GitHub Desktop.
Save nanderLP/a96a5b0c4a0e9177ee06cbc0e048fb9b to your computer and use it in GitHub Desktop.
Variable random string with crypto
const randomString = (length) => {
return Array.from(
window.crypto.getRandomValues(new Uint8Array(length / 2)),
(d) => d.toString(16).padStart(2, "0")
).join("");
}
const randomString = (length: number) => {
return Array.from(
window.crypto.getRandomValues(new Uint8Array(length / 2)),
(d) => d.toString(16).padStart(2, "0")
).join("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment