dev3dev
dev3dev

Reputation: 158

Math.random() VS crypto.randomInt() - Node.js

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

Answers (1)

AminM
AminM

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

Related Questions