frand
Pure functions for deterministically generating pseudorandom numbers
This module contains a small collection of simple "generators", i.e. pure functions that transform a seed
(really just a Number
) into a predictable output value.
You will usually want to change the seed after every use (typically by incrementing it) unless your goal is to get the same results multiple times.
usage
const percent integer boolean = const choose shuffle =
percent(seed)
Generate a number between 0
and 1
using seed
, exclusively.
if < 01 moneytype = 'gold' else moneytype = 'copper'
1
is not included in the set of possible return values, so this function is essentially a seedable version of Math.random()
.
integer(min, max, seed)
Generate an integer between min
and max
using seed
, inclusively.
{ return }
Unlike percent
, the upper number (max
) is included in the set of possible return values.
boolean(seed)
Choose either true
and false
based on the given seed
.
if for var connector of connectors floors else var connector = doors
The following two methods can be found in frand/array
.
choose(array, seed)
Chooses a random element from array
using seed
.
var card =
shuffle(array, seed)
Shuffles the items in array
in place using seed
.
install
npm install frand
license
MIT