bool(def) → {Array}

Since:
  • v1.0.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • Boolean? -> RandomGenerator

Generates a random boolean value

Parameters

true
NameTypeAttributesDescription
defBooleanA boolean value defaults to true

Returns

TypeDescription
ArrayAn Array pair with a new generator at [0] and the next seed at [1]
import { bool, step } from 'randoscando'

step(bool(), 'abc123') // => [false, 0.8987810940016061]

initialSeed(seed) → {Object}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • (seed) -> AleaSeed

Creates an initial seed using the alea algorithm

Parameters

NameTypeDescription
seedNumber | StringThe seed we want to use to create the randomness

Returns

TypeDescription
ObjectA alea object for seed generation and usage
import { initialSeed } from 'randoscando'

initialSeed('abc123') // => AleaSeedObject

map(list) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • RandomGenerators[] -> [RandomGenerator[], Seed]

Creates a single generator out of many, also supports nesting multiple maps

Parameters

NameTypeDescription
listArray.The Array of Generators we are going to map through

Returns

TypeDescription
ArrayAn Array pair with a new generator at [0] and the next seed at [1]
import { int, map, step } from 'randoscando'

step(map([
  int(1, 100),
  int(1, 100),
  int(1, 100)
]), 'abc123') // => [[99, 12, 50], 0.49460635893046856]

step(fnGen, seed) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • { value: any, step: (seed) => Array } -> AleaSeed -> [any, Seed]

Manually step through a random function in order to generate a value

Parameters

NameTypeDescription
fnGenObjectThe Generator function to step through and get a value from
seedSeedThe seed we want to use to create the randomness

Returns

TypeDescription
ArrayAn array pair with the value at [0] and the next seed at [1]
import { int, step } from 'randoscando'

step(int(1, 100), 'abc123') // => [90, 0.8986478650476784]
// Also curried
const stepper = step(int(1, 100))

stepper('abc123') // => [90, 0.8986478650476784]
stepper('wagh') // => [65, 0.646466348785907]

list(len, gen) → {RandomGeneratorResponse}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • List
Signature:
  • number -> RandomGenerator -> RandomGenerator

Creates a Random Generator responsible for building a random list of the desired length using the desired generator function

Parameters

NameTypeDescription
lenNumberA number value to tell list how many values to place in the array
genRandomGeneratorThe Random Generator we want to use to populate the array with

Returns

TypeDescription
RandomGeneratorResponseAn Array pair with a new generator at [0] and the next seed at [1]
import { englishLetter, list, step } from 'randoscando'

step(list(10, englishLetter()),'abc123') // => [['Y', 'N', 'C', 'U', 'N', 'F', 'H', 'D', 'O', 'A'], 0.8987810940016061]

pair(genOne, genTwo) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • List
Signature:
  • RandomGenerator -> RandomGenerator -> [RandomGenerator, Seed]

Takes in 2 generators to create a new generator and produce a random pair

Parameters

NameTypeDescription
genOnefunctionThe first generator function
genTwofunctionThe second generator function

Returns

TypeDescription
ArrayAn Array pair with a new generator at [0] and the next seed at [1]
import { int, pair, step } from 'randoscando'

step(
  pair(int(1, 100), int(1, 100)),
  'abc123'
) // => [[99, 10], 0.8987810940016061]

// pair is curried
cosnt fn = pair(int(1, 100))

step(fn(int(1, 100)), 'abc123') // => [[99, 10], 0.8987810940016061]

shuffle(list) → {Array}

Since:
  • v1.0.0
Kind:
  • function
Source:
Category:
  • List
Signature:
  • list -> RandomGenerator

Shuffles a provided list into a random order

Parameters

NameTypeDescription
listArray | StringThe List data set we are shuffling

Returns

TypeDescription
ArrayAn Array pair with a new generator at [0] and the next seed at [1]
import { shuffle, step } from 'randoscando'

const data = [1, 2, 3, 4, 5, 6]

step(shuffle(data), 'abc123') // => [[2, 3, 1, 6, 4, 5], 0.7790737589821219]

float(min, max) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • number -> number -> RandomGenerator

Creates a random number generator that will stay between the provided min and max

Parameters

NameTypeDescription
minNumberThe minimum the number can be
maxNumberThe maximum the number can be

Returns

TypeDescription
ArrayAn Array pair with a new generator at [0] and the next seed at [1]
import { float, step } from 'randoscando'

step(float(0, 1), 'abc123') // => [0.8986478650476784, 0.8986478650476784]

// float is also curried
const float = float(0)

step(float(1), 'abc123') // => [0.8986478650476784, 0.8986478650476784]

int(min, max) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • number -> number -> RandomGenerator

Creates a random number generator that will stay between the provided min and max

Parameters

NameTypeDescription
minNumberThe minimum the number can be
maxNumberThe maximum the number can be

Returns

TypeDescription
ArrayAn Array pair with a new generator at [0] and the next seed at [1]
import { int, step } from 'randoscando'

step(int(1, 100), 'abc123') // => [90, 0.8986478650476784]
step(int(1, 100), 'wagh') // => [65, 0.646466348785907]

// int is also curried
const int = int(1)

step(int(100), 'abc123') // => [90, 0.8986478650476784]

uniform(list) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • any[]-> RandomGenerator

Takes a list of values gives them all equal weight, and picks one

Parameters

NameTypeDescription
listArray.An array of values to choose from

Returns

TypeDescription
ArrayAn Array pair with a new generator at [0] and the next seed at [1]
import { step, uniform } from 'randoscando'

step(uniform([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 'abc123') // => [8, 0.8987810940016061]

weighted(list) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • [any, Number][] -> RandomGenerator

Takes a list of weighted values and creates a generator to pick one

Parameters

NameTypeDescription
listArrayAn array of weighted values

Returns

TypeDescription
ArrayAn Array pair with a new generator at [0] and the next seed at [1]
import { step, weighted } from 'randoscando'

step(weighted([
   ['a', 20],
   ['b', 20],
   ['c', 20],
   ['d', 20],
   ['e', 20],
 ]), 'abc123') // => ['d', 0.8987810940016061]

englishLetter(def) → {Array}

Since:
  • v1.0.0
Kind:
  • function
Source:
Category:
  • String
Signature:
  • string|undefined -> RandomGenerator

Takes a list of values gives them all equal weight, and picks one

Parameters

NameTypeDescription
defStringA value to set the value of letter to on creation of the generator (defaults to 'A')

Returns

TypeDescription
ArrayAn Array pair with a new generator at [0] and the next seed at [1]
import { englishLetter, step } from 'randoscando'

step(englishLetter(), 'abc123') // => ['W', 0.8987810940016061]