rauricoste-random
v2.2.8
Published
Summary ===
Downloads
8
Readme
Summary
This project provides random generators.
There is a uniform random generator, a gaussian random generator and
a 0
returning generator for debugging purpose.
Installation
npm install --save rauricoste-random
Usage
var Random = require("rauricoste-random")
var uniformGenerator = Random.simple;
var gaussianGenerator = Random.gaussian;
var zeroGenerator = Random.zero;
// returns a random number between 0 and 1 (uniform distribution)
uniformGenerator.nextRandom();
// returns a random number between 0 and 1 (gaussian distribution)
gaussianGenerator.nextRandom();
// returns 0
zeroGenerator.nextRandom();
Generator methods
nextRandom(): float
: returns a random number between 0 and 1nextNRandoms(n: integer): Array<float>
: returns an array ofn
random numbersnextNumber(min: float, max: float): float
: returns a random float number between min and maxnextInt(min: integer, max: integer): integer
: returns a random integer number between min and max (inclusive)nextChar(alphabet: string): string
: returns a random char contained in the stringalphabet
nextString(alphabet: string, length: integer = 32): string
: returns a random string of lengthlength
contained in thealphabet
nextReadableId(length: integer = 32): string
: returns a random string of lengthlength
using the alphabetabcdefghjkmnopqrstuvwxyz0987654321
shuffle(array)
: shuffles the array.array
is modified.pickOne(array)
: returns a random element of the arraypick(array, count: integer): {picked: Array, newArray: Array}
: pickscount
elements in thearray
. Thepicked
attribute of the returned object is the picked elements.newArray
is the array of the elements left.array
is not modified.