hrandom

Random number generator object.

npm install hrandom
4 downloads in the last week
18 downloads in the last month

An efficient Mersenne Twister implementation using the Java Random interface.

History

This code was originally in C, and then ported to Javascript. Havvy cleaned it up, removed the functions that weren't useful to me, and added some more functions.

The original authors are Takuji Nishimura and Makoto Matsumoto

Methods

The library itself is a constructor that returns a '''Random''' object. It is not necessary to use ''new'' before the constructor.

var Random = require('random');
var random = new Random(42);

The Random object implements next(), nextInt(), and nextBoolean() as per Java's API. nextElement and shuffle are some random functions that are often done to arrays. Each element in the range has an equal chance of being selected.

'''next()''' - Returns a value between [0..1) in increments of 2^-32. '''nextInt(length = 4294967295) ''' - Returns an int between [0..length). '''nextBoolean()''' - Returns either true or false.

'''nextElement(array)''' - Returns an element from the arrayj. '''shuffle(array)''' - Returns a new array with the contents of the passed in array shuffled.

npm loves you