bool(def) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Boolean? -> RandomGenerator
Generates a random boolean value
Parameters
Name | Type | Attributes | Description |
---|
def | Boolean | trueA boolean value defaults to true |
Returns
Type | Description |
---|
Array | An Array pair with a new generator at [0] and the next seed at [1] |
import { bool, step } from 'randoscando'
step(bool(), 'abc123')
initialSeed(seed) → {Object}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Creates an initial seed using the alea algorithm
Parameters
Name | Type | Description |
---|
seed | Number | String | The seed we want to use to create the randomness |
Returns
Type | Description |
---|
Object | A alea object for seed generation and usage |
import { initialSeed } from 'randoscando'
initialSeed('abc123')
map(list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
RandomGenerators[] -> [RandomGenerator[], Seed]
Creates a single generator out of many, also supports nesting multiple maps
Parameters
Name | Type | Description |
---|
list | Array. | The Array of Generators we are going to map through |
Returns
Type | Description |
---|
Array | An 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')
step(fnGen, seed) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
{ value: any, step: (seed) => Array } -> AleaSeed -> [any, Seed]
Manually step through a random function in order to generate a value
Parameters
Name | Type | Description |
---|
fnGen | Object | The Generator function to step through and get a value from |
seed | Seed | The seed we want to use to create the randomness |
Returns
Type | Description |
---|
Array | An array pair with the value at [0] and the next seed at [1] |
import { int, step } from 'randoscando'
step(int(1, 100), 'abc123')
const stepper = step(int(1, 100))
stepper('abc123')
stepper('wagh')
list(len, gen) → {RandomGeneratorResponse}
- Since:
- Kind:
- Source:
- Category:
- Signature:
number -> RandomGenerator -> RandomGenerator
Creates a Random Generator responsible for building a random list of the desired length using the desired generator function
Parameters
Name | Type | Description |
---|
len | Number | A number value to tell list how many values to place in the array |
gen | RandomGenerator | The Random Generator we want to use to populate the array with |
Returns
Type | Description |
---|
RandomGeneratorResponse | An 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')
pair(genOne, genTwo) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
RandomGenerator -> RandomGenerator -> [RandomGenerator, Seed]
Takes in 2 generators to create a new generator and produce a random pair
Parameters
Name | Type | Description |
---|
genOne | function | The first generator function |
genTwo | function | The second generator function |
Returns
Type | Description |
---|
Array | An 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'
)
cosnt fn = pair(int(1, 100))
step(fn(int(1, 100)), 'abc123')
shuffle(list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Shuffles a provided list into a random order
Parameters
Name | Type | Description |
---|
list | Array | String | The List data set we are shuffling |
Returns
Type | Description |
---|
Array | An 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')
float(min, max) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
number -> number -> RandomGenerator
Creates a random number generator that will stay between the provided min and max
Parameters
Name | Type | Description |
---|
min | Number | The minimum the number can be |
max | Number | The maximum the number can be |
Returns
Type | Description |
---|
Array | An Array pair with a new generator at [0] and the next seed at [1] |
import { float, step } from 'randoscando'
step(float(0, 1), 'abc123')
const float = float(0)
step(float(1), 'abc123')
int(min, max) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
number -> number -> RandomGenerator
Creates a random number generator that will stay between the provided min and max
Parameters
Name | Type | Description |
---|
min | Number | The minimum the number can be |
max | Number | The maximum the number can be |
Returns
Type | Description |
---|
Array | An Array pair with a new generator at [0] and the next seed at [1] |
import { int, step } from 'randoscando'
step(int(1, 100), 'abc123')
step(int(1, 100), 'wagh')
const int = int(1)
step(int(100), 'abc123')
weighted(list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
[any, Number][] -> RandomGenerator
Takes a list of weighted values and creates a generator to pick one
Parameters
Name | Type | Description |
---|
list | Array | An array of weighted values |
Returns
Type | Description |
---|
Array | An 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')
englishLetter(def) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
string|undefined -> RandomGenerator
Takes a list of values gives them all equal weight, and picks one
Parameters
Name | Type | Description |
---|
def | String | A value to set the value of letter to on creation of the generator (defaults to 'A') |
Returns
Type | Description |
---|
Array | An Array pair with a new generator at [0] and the next seed at [1] |
import { englishLetter, step } from 'randoscando'
step(englishLetter(), 'abc123')