Need to amend my script so that the random values generated from my range won't repeat when the function "myFill" is triggered. The range currently has 32 values - but only 5 non repeated values are required each time when triggered. Those values can be included again next time the function is triggered.
Link attached.
As an overview, the Script below is used in conjuction with these formula on the spreadsheet
Cell B2 =myFill(1,5,"H2:H33",J18)
Cell B3 =iferror(ArrayFormula(vlookup(B2,$H$2:$I$33,2,0)))
Appscript:
function tst(){
var rows = 1
var cols = 5
var range = "H2:H33"
myFill(rows, cols, range)
}
function myFill(rows, columns, range) {
var ss= SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
Logger.log(rows)
Logger.log(columns)
Logger.log(range)
var rng = sheet.getRange(range).getValues()
var output1 = [], l = rng.length;
for(var i=0; i<rows; i++) {
var output2 = [];
for(var j=0; j<columns; j++) {
output2.push(rng[Math.floor(Math.random() * l)][0]);
}
output1.push(output2);
}
return output1;
}