1

Any expert know to auto generate a random number every certain days later?

Example:

On every Monday, Google Sheets will auto change with a new random number:

https://docs.google.com/spreadsheets/d/1K8fJbRGRVB2Pv_X4MQT8WQgPkJfRPFq-apb7M61t6c8/edit?usp=sharing

acube
  • 25
  • 5

1 Answers1

1

Use Google Apps Script

I recommend using Google Apps Script because it has a time-dependent installable trigger feature. You may use the following script:

function randomNumber() {
  var min = 10000; //Set minimum value
  var max = 99999; //Set maximum value
  var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var num = Math.floor(Math.random() * (max - min + 1) ) + min; // The formula
  ss.getRange("B2").setValue(Math.round(num)); //Assigns the random value to B2.
}

Afterwards, you can set an installable trigger with this setup:

Trigger Setup

Please take note of the important settings for this trigger setup:

  1. Choose which function to run - the name of the function used
  2. Select event source - set to Time-driven
  3. Select type of time based trigger - set to Week timer
  4. Select day of week - set to Monday (based on your example)
  5. Select time of day - anytime you want the script to run(default value is Midnight to 1am)

If you do not know how to create an installable trigger, you may follow this tutorial video on YouTube: Google Apps Script Triggers Explained. You may skip to 9:42 (How to add installable triggers part).

Output

After saving/running the script and adding the installable triggers, the spreadsheet is expected to update cell B2 every Monday (Midnight to 1AM based on the current installable trigger setup).

Output

References:

  1. Math.random
  2. Installable Triggers
PatrickdC
  • 1,385
  • 1
  • 6
  • 17
  • Thank you! I tested and this work perfectly. You are great with very detailed explanation! – acube May 29 '22 at 09:11