1.1.0 • Published 7 years ago

random-helpers v1.1.0

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

Random Helpers

Random Helpers provides random helper functions.

Installation

npm install random-helpers

Example

var randomHelpers = require("random-helpers");

console.log('Coin flip:');
if (randomHelpers.randomBoolean()) console.log('Heads');
else console.log('Tails');

Usage

randomHelpers.randomArraySubset(array)

Returns a subset of array consisting of a random combination of sub-elements.

Parameters:

ParameterTypeDescription
arrayarrayThe array to generate a subset from

randomHelpers.randomBoolean()

Generates a random boolean.

Parameters: None

randomHelpers.randomIndex(array)

Generates a random integer in the range [0, array.length).

Parameters:

ParameterTypeDescription
arrayarrayThe array to generate an index from

randomHelpers.randomIntegerInclusive(min, max)

Generates a random integer in the range min, max.

Parameters:

ParameterTypeDescription
minintegerThe minimum integer value to generate
maxintegerThe maximum integer value to generate

randomHelpers.randomItem(array)

Returns a random item from array.

Parameters:

ParameterTypeDescription
arrayarrayThe array to return an item from

randomHelpers.randomNumber(min, max)

Returns a random number in the range [min, max).

Parameters:

ParameterTypeDescription
minnumberThe minimum number value to generate
maxnumberThe maximum number value to generate

randomHelpers.randomVariable()

Returns a random variable, of type boolean, null, undefined, number, string, function, or object. If the variable is of type object, it will either be an array, or plain object.

Parameters: None

randomHelpers.randomVariableExcluding(typesToExclude)

Returns a random variable as in randomHelpers.randomVariable, but will not return a variable with a type specified in typesToExclude.

Parameters:

ParameterTypeDescription
typesToExcludestring or array of stringsThe data types that the random variable should not be. Valid types include boolean, null, undefined, number, string, function, object, array, and plainObject. If typesToExclude includes object, then array and plainObject are both implicitly excluded. If typesToExclude is undefined, then no data types will be excluded.
1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago