Created
March 4, 2019 16:14
-
-
Save opendoug/9a859d0a843220fcf360f2e5c0ce5722 to your computer and use it in GitHub Desktop.
Random Chore Chart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!