New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

seedrand

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

seedrand

Use Math.seed() to get test your Math.random()-based functions.

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

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 );
a = Math.random();

Math.seed( mySeed );
b = Math.random();

console.log( a === b ); // true
</script>

NodeJS

require( 'seedrand' );

var mySeed = +new Date(),
    a, b;

Math.seed( mySeed );
a = Math.random();

Math.seed( mySeed );
b = 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”.

Keywords

random

FAQs

Package last updated on 24 Jun 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts