Following are 4 different methods to generate random numbers in Excel
Table of Contents
RAND Function
The RAND function in Excel can be used to generate a random number between 0 and 1.
The RAND function is a volatile function and will update every when the worksheet is recalculated.
RANDBETWEEN Function
The RANDBETWEEN function returns a random number between two specified values in it.
For example, the formula =RANDBETWEEN(10,75) will return a random number between 10 and 75.
The RANDBETWEEN function also is a volatile function and will update every when the worksheet is recalculated.
RANDARRAY Function
The RANDARRAY function is of the new Dynamic Array Function which can return an array of random numbers.
The RANDARRAY function accepts 5 arguments which can used to specify the number of Rows, Columns, Number limits and type of number, whether Integer or Decimal.
=RANDARRAY(9,5,-15,50,TRUE) will return an array of 45 Integers between -15 and 50.
For decimal numbers, use FALSE instead of TRUE.
Excel Macro to generate random number
The following VBA code when executed will generate a random number between 50 and 999, in the cell C3
Sub CreateRandomNumber() Range("C3").Value = Int((999 - 50 + 1) * Rnd + 50) End Sub