Created
March 25, 2024 21:26
-
-
Save theohogberg/2cf38dae63ca9406444fdce7a6474fbe to your computer and use it in GitHub Desktop.
TS: random32 * x hex generator
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
export const getRandom32x = (x: number = 1): string => { | |
if (x > 8) x = 8; | |
const uint32Array = new Uint32Array(x); | |
crypto.getRandomValues(uint32Array); | |
return uint32Array.reduce((a: string, v: number) => { | |
return a + v.toString(16).padStart(8, '0'); | |
}, ""); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment