Skip to content

Instantly share code, notes, and snippets.

@KooiInc
Created May 18, 2023 16:13
Show Gist options
  • Save KooiInc/0e75891b552b5573f25585ebb8de2053 to your computer and use it in GitHub Desktop.
Save KooiInc/0e75891b552b5573f25585ebb8de2053 to your computer and use it in GitHub Desktop.
Create random number using crypto
function randomNumber (min = 0, max = Number.MAX_SAFE_INTEGER) {
return Math.floor( ( [...crypto.getRandomValues( new Uint32Array(1))][0] / 2**32 ) * (max - min + 1) + min );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment