Skip to content

Instantly share code, notes, and snippets.

@opendoug
Created March 4, 2019 16:14
Show Gist options
  • Save opendoug/9a859d0a843220fcf360f2e5c0ce5722 to your computer and use it in GitHub Desktop.
Save opendoug/9a859d0a843220fcf360f2e5c0ce5722 to your computer and use it in GitHub Desktop.
Random Chore Chart
function shuffle() {
// Shuffle the array
var array = [['Doug'], ['Christina'], ['Afton'], ['Quinnlyn']];
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
Logger.log(array);
// Write the array to a range
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getRange('A3:D3')
range.setValues([array]);
}
@opendoug
Copy link
Author

opendoug commented Mar 4, 2019

Create a Google Sheet. A1:D1 is for your title A2:D2 is for your chore names. A3:D3 is the range that your array of names will be randomly written in, so each time the script is run the array is re-randomized and re-written to the Sheet. Keep your kids guessing! Allow the malevolence of randomness dictate your house work! Laugh as children feel the cold wrath of random number generation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment