Created
March 3, 2025 13:30
-
-
Save muthu32/d6034cba2d710dd03b76faa36911bf31 to your computer and use it in GitHub Desktop.
Insecure Random Fortify Math.random alternative
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
function generateRandom() { | |
// Generate a secure random 32-bit unsigned integer | |
const randomBuffer = new Uint32Array(1); | |
window.crypto.getRandomValues(randomBuffer); | |
// Convert the random integer to a floating-point number between 0 (inclusive) and 1 (exclusive) | |
return randomBuffer[0] / (0xFFFFFFFF + 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for nodejs use below code