Reputation: 158
What is the difference between the way Math.random()
and crypto.randomInt()
work in node.js?
And if I will run them in a loop for a long time, is it possible for me to get the same result an amount of times that exceeds the statistics?
Upvotes: 2
Views: 2808
Reputation: 856
Math.random() uses a basic psuedo-random algorithm that is not necessarily cryptographically secure.
The requirements for randomness for cryptographic purposes are generally much more stringent than what you would need if you just want to randomize some motion in an animation.
If you're using it for security then use the crypto version.
Upvotes: 3