seedrand

0.1.0 • Public • Published

seedrand.js

seedrand.js is a micro library which allows you to seed Math.random(). It’s mainly written for testing functions that require random numbers.

Usage

The library can be included server- and/or client-side. It moves the original Math.random to Math._random, and use a custom pseudo-random number generator (PRNG) to replace it.

Client-side

<script src="/path/to/seedrand.min.js"></script>
<script>
var mySeed = +new Date(),
    a, b;
 
Math.seed( mySeed );
= Math.random();
 
Math.seed( mySeed );
= Math.random();
 
console.log( a === b ); // true
</script> 

NodeJS

require( 'seedrand' );
 
var mySeed = +new Date(),
    a, b;
 
Math.seed( mySeed );
= Math.random();
 
Math.seed( mySeed );
= Math.random();
 
console.log( a === b ); // true

Install

On the client-side, include the seedrand.min.js file in your page. On the server-side, install the seedrand npm package:

[sudo] npm -g install seedrand

Acknowledgments

The code of the PRNG is based on Adam Hyland’s implementation of “Webkit2’s crazy invertible mapping generator”.

Readme

Keywords

none

Package Sidebar

Install

npm i seedrand

Weekly Downloads

0

Version

0.1.0

License

MIT

Last publish

Collaborators

  • bfontaine