T
T
TomasF2021-08-25 20:03:38
Google Sheets
TomasF, 2021-08-25 20:03:38

How to make RANDBETWEEN function triggered by date?

Is it possible to have the RANDBETWEEN function change value only by date, such as once a day or once a month?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2021-08-27
@TomasF

The formula to implement this process will require iterative calculations and a very complex formula.
Try using a trigger on a function generateValue:

function generateValue() {
  var spreadsheet = SpreadsheetApp.getActive();
  var from = 1;
  var to = spreadsheet.getRange('Sheet1!C5').getValue();
  var rand = randBetween_(from, to);
  spreadsheet.getRange('Sheet1!D5').setValue(rand);
}


function randBetween_(from, to){
  return Math.floor(Math.random()*(to - from + 1) + from);
}

The original solution contains a similar problem, only the first value fromfor randBetween_ equals 1, and the second tois taken from the Table. The trigger is configured in such a way that the data in the cell is D5updated periodically.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question