MinRand

new MinRand(dataset, usedDataPointsopt)

Creates a new MinRand instance
Parameters:
NameTypeAttributesDefaultDescription
datasetArrayAn array containing the dataset
usedDataPointsObject<optional>
{}A key-value object containing the arrays of used datapoints. Converted to a Map internally.
Throws:
TypeError

Methods

addDatasetPoint(value)

Adds a value to the dataset array
Parameters:
NameTypeDescription
value*The value to add

addUsedDataPoint(key, datapoint)

Adds a used datapoint to a key
Parameters:
NameTypeDescription
key*The key
datapoint*The datapoint to add
Throws:
  • If the key does not exist or if the datapoint is not already in the dataset
    Type
    NotExistsError
  • If the datapoint already exists for the specified key
    Type
    ExistsError

addUsedDataPointKey(key, forceopt)

Adds an empty used data point array for the specified key
Parameters:
NameTypeAttributesDefaultDescription
key*The key
forceboolean<optional>
falseWhether to override an existing key
Throws:
An error thrown if the key already exists
Type
ExistsError

getDataset() → {Array}

Returns the dataset
Returns:
An array containing the dataset
Type: 
Array

getEventEmitter() → {EventEmitter}

Returns the EventEmitter
Returns:
The EventEmitter
Type: 
EventEmitter

getRandomDataPoint(key) → {*}

Gets a random datapoint not in the used datapoint store specified by key, and adds this to the used datapoint array for the key
Parameters:
NameTypeDescription
key*The key
Returns:
The random datapoint
Type: 
*

getUsedDataPointArray(key) → {Array|undefined}

Gets the used datapoints for the specified key
Parameters:
NameTypeDescription
key*The key
Returns:
An array of used datapoints for this key. Undefined if it does not exist
Type: 
Array | undefined

getUsedDataPoints() → {Map}

Returns the used data points map
Returns:
The used data points map
Type: 
Map

getUsedResetPercentage() → {double}

Returns the usage percentage at which the first half of the used datapoint store will be removed
Returns:
The percentage in decimal form
Type: 
double

removeDatasetPoint(value)

Removes a value from the dataset array, and all used datapoint arrays
Parameters:
NameTypeDescription
value*The value to remove

removeUsedDataPointKey(key)

Removes a used datapoint key
Parameters:
NameTypeDescription
key*The key

setDataset(dataset)

Sets the dataset
Parameters:
NameTypeDescription
datasetArrayAn array containing the dataset
Throws:
TypeError

setUsedDataPointArray(key, array)

Sets the used datapoints for the specified key
Parameters:
NameTypeDescription
key*The key
array*The array of datapoints
Throws:
TypeError

setUsedResetPercentage(percentage)

Sets the usage percentage at which the first half of the used datapoint store will be removed
Parameters:
NameTypeDescription
percentagedoubleA percentage in decimal form between 0.01 and 0.99 (inclusive)
Throws:
  • TypeError
  • RangeError

Events

reset

The reset event fires when the first half of the used datapoints for the specified key is removed
Type:
  • object
Properties
NameTypeDescription
key*The key that was reset