Secure Integers In Node
You can use both functions as follows:
Good random numbers rely on a lot of entropy (chaos so to say). Math.random does not have much entropy. In fact, there are even good ways to guess which number Math.random probably spills out next when calling it repeatedly. The crypto module in Node doesn’t take any current timestamps or things like that into account and instead relies on more secure entropy.
If you ever need a random number someone should not be able to guess easily, rely on the crypto module instead of Math.random.