Last active
October 2, 2022 13:45
-
-
Save nanderLP/a96a5b0c4a0e9177ee06cbc0e048fb9b to your computer and use it in GitHub Desktop.
Variable random string with crypto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const randomString = (length) => { | |
return Array.from( | |
window.crypto.getRandomValues(new Uint8Array(length / 2)), | |
(d) => d.toString(16).padStart(2, "0") | |
).join(""); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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