Git Product home page Git Product logo

pseudo-math-random's Introduction

pseudo-math-random

Same algorithm as Math.random but with a custom seed.
Useful for reproducible tests and benchmarks. Same API as math-random-seed which uses crypto (secure) while this uses xorshift128+ (60x faster).

npm status node Travis build status JavaScript Style Guide

Usage

const pmr = require('pseudo-math-random')
const random = pmr('a seed')

console.log(random()) // Always 0.32911525012180043
console.log(random()) // Always 0.5563213847156248

API

random = pmr([seed])

Create a new random number generator. The seed argument must be a string or Buffer. It is hashed once to counter short or zero-filled seeds. If no seed is provided one will be generated.

num = random()

Get a floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive). Does not provide cryptographically secure random numbers.

Install

With npm do:

npm install pseudo-math-random

Benchmark

$ node benchmark.js
node v10.14.1
pseudo-math-random x 23,050,253 ops/sec ±0.24% (94 runs sampled)
math-random-seed x 377,674 ops/sec ±1.50% (86 runs sampled)
Fastest is pseudo-math-random

NB. Speed isn't everything. Decide for yourself which properties you need.

License

MIT © 2019-present Vincent Weevers

pseudo-math-random's People

Contributors

greenkeeper[bot] avatar vweevers avatar

Stargazers

 avatar  avatar

Watchers

 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.