hrandom

1.1.2 • Public • Published

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(list)''' - Returns an element from the list. '''nextElements(list, count)''' - Returns a new array with ''count'' random elements from ''list''.

'''shuffle(array)''' - Returns a new array with the contents of the passed in array shuffled. '''shuffleInPlace(list)''' - As the name says, shuffles a list in place, mutating the list.

Readme

Keywords

none

Package Sidebar

Install

npm i hrandom

Weekly Downloads

1

Version

1.1.2

License

none

Last publish

Collaborators

  • havvy