Random number generator formula

A random number generator is a tool that allows users to generate a random number within a specified range. This can be useful for many applications, such as generating random passwords, selecting a random winner in a contest, or simulating random events in a game.

To create a custom formula for a random number generator in Google Sheets using Apps Script, follow these steps:

  1. Open a new or existing Google Sheet.
  2. Click on “Tools” and then “Script editor” to open the Apps Script editor.
  3. In the Apps Script editor, create a new function called “randBetween” that takes two arguments: the minimum value and the maximum value of the desired range.
  4. Inside the “randBetween” function, use the “Math.random()” method to generate a random decimal between 0 and 1.
  5. Multiply the decimal by the range of values you want to generate (i.e. the difference between the maximum and minimum values).
  6. Add the minimum value to the result to shift the range of random numbers to the desired minimum value.
  7. Return the result as the output of the function.

Here’s an example code for a custom formula to generate a random number between 1 and 100:

function randBetween(min, max) {
  var range = max - min + 1;
  var randomNum = Math.floor(Math.random() * range) + min;
  return randomNum;
}

To use this custom formula in your Google Sheet, simply enter “=randBetween(1,100)” into any cell where you want a random number between 1 and 100 to be generated.

This custom formula can be modified to generate random numbers within any desired range by changing the minimum and maximum values in the function call.