array_rand
v1.0.7
Published
Returns the specified number of random elements from the array.
Downloads
14
Maintainers
Readme
array_rand
Returns specified number of random objects from the array. Given an array, this module will fetch the specified number of random elements within a range in the array.
Installing
npm install array_rand
Functions
The array_rand module has two versions of the functions :
Async version
getRandomObjectsInRange(array, count, startIndex, endIndex, callback)
Sync version
getRandomObjectsInRangeSync(array, count, startIndex, endIndex)
Where:
array - The array used
count - The count of random objects that you need from the array
startIndex - The starting index of the array
endIndex - The ending index of the array
Usage
var array_rand = require('array_rand');
var arr = [1,2,3,4,5,6];
var result = array_rand.getRandomObjectsInRangeSync(arr, 3, 1, 5);
array_rand.getRandomObjectsInRange(arr, 3, 1, 5, function(err, result) {
// Do operation on result
});
// Results any three elements from the array "arr" in the given range