Skip to content

Instantly share code, notes, and snippets.

@aborruso
Created April 21, 2020 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aborruso/68547b8df77423226bf7ac0b57d9b73e to your computer and use it in GitHub Desktop.
Save aborruso/68547b8df77423226bf7ac0b57d9b73e to your computer and use it in GitHub Desktop.
/**
* This function by Vadorequest generates a random number in the "randomNumber" sheet.
*
* It needs to be triggered with a Google Apps Scripts trigger at https://script.google.com/home/:
* - Select project and add trigger
* - Choose which function to run: triggerAutoRefresh
* - Select event source: Time-driven
* - Select type of time based trigger: Minutes timer
* - Select minute interval: 10 minutes (to avoid too many requests)
**/
// Updates cell A1 in "randomNumber" with a random number
function triggerAutoRefresh() {
SpreadsheetApp.getActive().getSheetByName('doNotDelete').getRange(1, 1).setValue(getRandomInt(1, 200));
}
// Basic Math.random() function
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment