A Tiny Random Utility Generator
- Alea RNG
- Seedable
- Random
- number
- between
- chance
- itemFromArray
- entryFromObject
- keyFromObject
- Tested with Jest
- 2kb minified (<1kb minified + gzipped)
git clone https://github.com/RetroVX/random.git
Or download from Zip
constRandom=require('./path/to/random.js');constseed='mySeed';constrandom=newRandom(seed);importRandomfrom"./path/to/random.mjs";constseed='mySeed';constrandom=newRandom(seed);<scripttype="text/javascript" src="path/to/random.umd.js"></script>constseed='mySeed';constrandom=newwindow.random(seed);// generate a random number between 0 and 1.// use this in place of Math.random()random.gen();->0.9401234467513859// generate a random number with a max number (defaults to 100 if undefined)random.number(100);->42// generates a random number using a min and max numberrandom.between(1,25);->17// percent chance to happenrandom.chance(50)->true// picks a random item from an arrayrandom.itemFromArray([1,2,3,4,5]);->2// picks a random key/value pair and outputs as an arrayrandom.entryFromObject({prop1: 'hello',prop2: 'world'});->['prop1','hello']// picks a random key from an objectrandom.keyFromObject({prop1: 'hello',prop2: 'world'});->'prop2'// new seedrandom.newGenerator(seed);Alea
- Johannes Baagøe baagoe@baagoe.com, 2010