Skip to content

Repository files navigation

Random

A Tiny Random Utility Generator

License: MIT

Features

  • Alea RNG
  • Seedable
  • Random
    • number
    • between
    • chance
    • itemFromArray
    • entryFromObject
    • keyFromObject
  • Tested with Jest
  • 2kb minified (<1kb minified + gzipped)

Install

git clone https://github.com/RetroVX/random.git

Or download from Zip

Node & Common

constRandom=require('./path/to/random.js');constseed='mySeed';constrandom=newRandom(seed);

Module

importRandomfrom"./path/to/random.mjs";constseed='mySeed';constrandom=newRandom(seed);

UMD

<scripttype="text/javascript" src="path/to/random.umd.js"></script>
constseed='mySeed';constrandom=newwindow.random(seed);

Examples

// 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);

Credit

Alea

Version 1.3.0

About

Random Seeded Generator

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages