Git Product home page Git Product logo

nodejs-secure-random's Introduction

Build Status

Purpose

Javascripts Math.random is not very random. This library attempts to use the NodeJS crypto library to generate random numbers more randomly. Additionally, getting a random int inside of a range does not use modulo in order to provide a more evenly distrubuted set of numbers.

For why using modulo to find the int for a range is bad see here(http://mathoverflow.net/questions/35556/skewing-the-distribution-of-random-values-over-a-range).

Randomness

According to ent the entropy of Node's Math.random is 3.304235. Using this module the entropy is 3.451241. I am not able to determine how much this is but atleast secure_random is better. If anyone has ideas to improve the code or how to test it those would be greatly appreciated.

Install

npm install secure_random

or

git clone [email protected]:my8bird/nodejs-secure-random.git

Usage

var random = require('./random');

// Just get random data to use as you wish
random.getRandomInt(function(err, value) {
   // This value will be between 0 and MAX_INT where MAX_INT is a 32bit value
   console.log("Look ma I got some entropy", value);
   }
);

// Get a random int between to values
random.getRandomInt(10, 100, function(err, value) {
   // The value will between 10-100
   console.log("Look ma I got some entropy", value);
   }
);

nodejs-secure-random's People

Contributors

mkilling avatar my8bird avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.