11

I am looking for a cryptographically secure number generator for node.js. Afaik. Math.random() does not meet these requirements. Is there any nodejs lib which can generate cryptographically secure numbers?

3
  • 2
    Are you looking for a true random number generator, or just a psuedo-random number generator that's cryptographically secure? Anyways, product recommendations are off-topic here. Commented Dec 6, 2016 at 0:44
  • Can you first explain what your requirements are and what about Math.random() does not meet those requirements? You have not described your actual requirements so we can't really know what would be needed for your solution.
    – jfriend00
    Commented Dec 6, 2016 at 0:51
  • @XiongChiamiov Cryptographically secure is enough if true random is not possible.
    – inf3rno
    Commented Dec 6, 2016 at 6:16

2 Answers 2

16

You are correct that Math.random() is not secure. If you want a CSPRNG in Node.js, crypto.randomBytes() is what you're looking for.

2

There are a few libs available, but I need to be certain whether they are really true random.

Any one who considers arithmetical methods of producing random digits is, of course, in a state of sin.

Basically, no library can generate any "really true random"s. Lately some processors include support for hardware RNGs, which allows (hopefully) "really true random"s to be generated.

That being said, there are -very- few applications for which a CSPRNG will not suffice. In fact, CSPRNGs offer such good quality randomness that I can't think of any.

2
  • Thanks! Then it was a misunderstanding. What I meant is cryptographically secure instead of true random.
    – inf3rno
    Commented Dec 6, 2016 at 6:20
  • I edited the question.
    – inf3rno
    Commented Dec 6, 2016 at 11:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .