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
NodeJS
; var mySeed = + a b; Math;a = Math; Math;b = Math; console; // 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”.