Last active
July 3, 2023 17:14
-
-
Save azechi/01cb8908a41c132ad95f54bbb91ad5aa to your computer and use it in GitHub Desktop.
Generate a random base32 string(length:6) using Web Crypto API
This file contains hidden or 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 base = "abcdefghijklmnopqrstuvwxyz234567" //a-z, 2-7 | |
const array = new Int32Array(1) | |
window.crypto.getRandomValues(array) | |
const i = array[0] | |
var result = | |
base[i >>> 27 & 0x1f] + | |
base[i >>> 22 & 0x1f] + | |
base[i >>> 17 & 0x1f] + | |
base[i >>> 12 & 0x1f] + | |
base[i >>> 7 & 0x1f] + | |
base[i >>> 2 & 0x1f] | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very good my friend thank you