secure-random-number

1.0.0 • Public • Published

secure-random-number

Math.random, but slightly more unpredictable!

What?

Math.random isn't actually random, and is, in-fact, very predictable. This library uses NodeJS's built-in crypto module or crypto.getRandomValues() on web browsers for "unpredictable" randomness.

Yeah, but something like this already exists, right?

Right, however they tend to create a random uint32, then divide it by 2 ** 32. Which means only (2 ** 32 - 1) possible values, at a range from 0 to 0.9999999997671694. Which is GROSS, and DISGUSTING. This library works by filling a 64-bit float's entire 52-bit mantissa with random values! Which allows for 2 ** 52 (ish) possible values, at a range from 0 to 0.9999999999999998! Which, while not perfect, is a whole lot better.

Note: I made this package years ago but never published it for some reason.

/secure-random-number/

    Package Sidebar

    Install

    npm i secure-random-number

    Weekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    3.1 kB

    Total Files

    3

    Last publish

    Collaborators

    • aritz-cracker