Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Return randome unique values from a array
- *
- * @param {A1:D10} data - Your dataset.
- * @param {5} amount - number of values returned.
- * @return Unique values from input
- * @customfunction
- */
- function RNDUNIQ(data, amount) {
- const arr1d = [].concat(...data);
- const result = [];
- const numbers = [];
- const arrLength = arr1d.length;
- do {
- const n = rand(arrLength);
- if (numbers.indexOf(n) < 0){
- numbers.push(n); }
- } while (numbers.length < amount)
- for ( var i = 0; i < amount; i++ ) {
- result.push(arr1d[numbers[i]]);
- }
- return result;
- }
- function rand(length) {
- return Math.floor(Math.random() * length);
- }
Add Comment
Please, Sign In to add comment