Home Reference Source
public class | source

random

Static Method Summary

Static Public Methods
public static

bool(): *

Return a random Boolean value

public static

chance(limit: *): boolean

Returns a boolean result based on limit

public static

choose(list: Array, flat: Boolean): *

Return an item from an array of arrays where the first index in each sub-array denotes the weight

public static

float(): *

Returns a float in [0, 1) (uniform distribution)

public static

hex(len: *): *

public static

init(seed: number)

Must be called before any other methods can be called to initialize MersenneTwister

public static

item(list: Array): *

Returns a random index from a list

public static

key(obj: Object): *

Returns a random key of a provided object

public static

ludOneTo(limit: number): *

Returns a float in [1, limit).

public static

number(limit: number): *

Returns an integer in [0, limit) (uniform distribution)

public static

pick(obj: *): *

Recursively iterate over array until non-array item identified If item is a function, evaluate it with no args

public static

pop(arr: *): *

Removes and returns a random item from an array.

public static

range(start: number, limit: number): *

Returns an integer in [start, limit) (uniform distribution)

public static

shuffle(arr: *)

Returns arr shuffled

public static

shuffled(arr: *): *

Returns a shuffled copy of arr

public static

subset(list: *, limit: *): Array

Select an array containing a subset of 'list'

public static

use(obj: *): *

public static

weighted(list: Array): *

Return a flattened list of weighted values [{w: 1, v: 'foo'}, {w: 1, v: 'bar'}]

Static Public Methods

public static bool(): * source

Return a random Boolean value

Return:

*

public static chance(limit: *): boolean source

Returns a boolean result based on limit

Params:

NameTypeAttributeDescription
limit *

Return:

boolean

public static choose(list: Array, flat: Boolean): * source

Return an item from an array of arrays where the first index in each sub-array denotes the weight

Params:

NameTypeAttributeDescription
list Array

Array of arrays

flat Boolean

Indicates whether we should iterate over the arrays recursively

Return:

*

public static float(): * source

Returns a float in [0, 1) (uniform distribution)

Return:

*

public static hex(len: *): * source

Params:

NameTypeAttributeDescription
len *

Return:

*

public static init(seed: number) source

Must be called before any other methods can be called to initialize MersenneTwister

Params:

NameTypeAttributeDescription
seed number
  • nullable: true

Value to initialize MersenneTwister

public static item(list: Array): * source

Returns a random index from a list

Params:

NameTypeAttributeDescription
list Array

Return:

*

public static key(obj: Object): * source

Returns a random key of a provided object

Params:

NameTypeAttributeDescription
obj Object

Return:

*

public static ludOneTo(limit: number): * source

Returns a float in [1, limit). The logarithm has uniform distribution.

Params:

NameTypeAttributeDescription
limit number

Return:

*

public static number(limit: number): * source

Returns an integer in [0, limit) (uniform distribution)

Params:

NameTypeAttributeDescription
limit number

Return:

*

public static pick(obj: *): * source

Recursively iterate over array until non-array item identified If item is a function, evaluate it with no args

Params:

NameTypeAttributeDescription
obj *

Return:

*

public static pop(arr: *): * source

Removes and returns a random item from an array.

Params:

NameTypeAttributeDescription
arr *

Return:

*

public static range(start: number, limit: number): * source

Returns an integer in [start, limit) (uniform distribution)

Params:

NameTypeAttributeDescription
start number
limit number

Return:

*

public static shuffle(arr: *) source

Returns arr shuffled

Params:

NameTypeAttributeDescription
arr *

public static shuffled(arr: *): * source

Returns a shuffled copy of arr

Params:

NameTypeAttributeDescription
arr *

Return:

*

public static subset(list: *, limit: *): Array source

Select an array containing a subset of 'list'

Params:

NameTypeAttributeDescription
list *
limit *

Return:

Array

public static use(obj: *): * source

Params:

NameTypeAttributeDescription
obj *

Return:

*

public static weighted(list: Array): * source

Return a flattened list of weighted values [{w: 1, v: 'foo'}, {w: 1, v: 'bar'}]

Params:

NameTypeAttributeDescription
list Array

Return:

*