Skip to content

Instantly share code, notes, and snippets.

@theohogberg
Created March 25, 2024 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theohogberg/2cf38dae63ca9406444fdce7a6474fbe to your computer and use it in GitHub Desktop.
Save theohogberg/2cf38dae63ca9406444fdce7a6474fbe to your computer and use it in GitHub Desktop.
TS: random32 * x hex generator
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