Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9632

App Script to Random Range with 10 % of total data

$
0
0

I have a table with 20 rows of data.I want to randomize the data with 10% of the total data.The script I made is like this:

function shuffleSheet() {  var ss = SpreadsheetApp.getActiveSpreadsheet();  var sheet = ss.getActiveSheet();  var range = sheet.getRange('A2:D21');  range.setValues(shuffleArray(range.getValues()));    }    function shuffleArray(array) {  var i, j, temp;  for (i = array.length - 1; i > 0; i--) {    j = Math.floor(Math.random() * (i + 1));    temp = array[i];    array[i] = array[j];    array[j] = temp;  }  return array;}

After I run the script, the results are the data is randomized all the data.enter image description here

The result what i want, it can see in below :enter image description here


Viewing all articles
Browse latest Browse all 9632

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>