1.0.3 • Published 3 years ago
@llagache/seedablejs v1.0.3
SeedableJS
A simple class based seedable random generator in javascript.
About
The goal is to provide an easy to use seeded random generator comming with set of helpers to quickly generate random numbers, strings, arrays ...
It use a combinaison of the xmur3 hashing function and the mulberry32 pseudo random generator https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript/47593316%2347593316
Usage
npm install @llagache/seedablejs
Example :
import Seedable from "@llagache/seedablejs";
const s = new Seedable("seed");
var randomValue = s.value();
Constructor :
/**
* Create a new Seedable random generator
* @param {string?} optional seed
*/
new Seedable(seed)
Methods :
/**
* Update seed
* @param {string} seed
*/
updateSeed(seed=null)
/**
* @returns random number between 0 & 1
*/
value()
/**
* @param {number} min
* @param {number} max
* @returns random number between min & max
*/
range(min, max)
/**
* @param {array} array
* @returns random element from an array
*/
element(array)
/**
* @param {array} array
* @param {number} min
* @param {number} max
* @param {bool} autorizeDuplicate
* @returns mutiple (between min & max) random elements from an array
*/
elements(array, min, max, autorizeDuplicate=true)
/**
* @param {*} sizeX
* @param {*} sizeY
* @returns random image url from piscsum.photos
*/
image(sizeX, sizeY)
/**
* @param {number} min
* @param {number} max
* @returns random lorem ipsum sentence
*/
lorem(min, max)
/**
* @param {function} factoryFn
* @param {number} length
* @param {bool} unique
* @returns random array of elements based on the factoryFn
*/
pool(factoryFn, length, unique = false)
/**
* @param {date} start
* @param {date} end
* @returns random date between start & end
*/
date(start, end)
/**
* @param {number} length
* @returns random string using these char [ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]
*/
string(length)
Static Methods :
/**
* @param {number} length
* @returns random seed
*/
Seedable.randomSeed()
Author
Lagache Louis (@llagache_dev)