In excel the RAND() function returns a number greater than or equal to 0 (zero) and less than 1. Combining the RAND() function with a few other functions makes it possible to create random numbers, text, dates and time values.

Table of contents

  1. Random numbers
  2. Random text strings
  3. Random date values
  4. Random time values


Random numbers

Formula in cell A1:

=RAND()

RAND() function returns a number greater than or equal to 0 (zero) and less than 1 every time a sheet is recalculated. Pressing F9 recalculates all sheets in all open workbooks. The RAND function is a volatile function.

How to return numbers between or equal to 0 and 100?

Formula in cell A3:

=ROUNDUP(RAND()*101;0)-1

How to return numbers between or equal to -50 and 50?

Formula in cell A5:

=ROUNDUP(RAND()*101;0)-51

ROUNDUP(number, num_digits) - Rounds a number up, away from zero.

Random text strings

A character in excel is represented by a number. A to Z are 65 to 90 and a to z are 97 to 122. =CHAR(number) returns the character specified by the code number from the character set of your computer. You can use the CHAR, RAND and ROUNDUP function to return random characters, let me show you how.

A random uppercase letter

Formula in A1:

=CHAR(ROUNDUP(RAND()*26,0)-1+65)

A random lowercase letter

Formula in B1:

=CHAR(ROUNDUP(RAND()*26,0)-1+97)

A random lowercase or uppercase letter

Formula in C1:

=IF(RAND()<0.5,CHAR(ROUNDUP(RAND()*26,0)-1+65),CHAR(ROUNDUP(RAND()*26,0)-1+97))

Three random uppercase letters

Formula in A2:

=CHAR(ROUNDUP(RAND()*26, 0)-1+65)&CHAR(ROUNDUP(RAND()*26, 0)-1+65)&CHAR(ROUNDUP(RAND()*26, 0)-1+65)

Three random lowercase letters

Formula in B2:

=CHAR(ROUNDUP(RAND()*26, 0)-1+97)&CHAR(ROUNDUP(RAND()*26, 0)-1+97)&CHAR(ROUNDUP(RAND()*26, 0)-1+97)

Three random lowercase and uppercase letters

Formula in C2:

=IF(RAND()<0.5, CHAR(ROUNDUP(RAND()*26, 0)-1+65), CHAR(ROUNDUP(RAND()*26, 0)-1+97))&IF(RAND()<0.5, CHAR(ROUNDUP(RAND()*26, 0)-1+65), CHAR(ROUNDUP(RAND()*26, 0)-1+97))&IF(RAND()<0.5, CHAR(ROUNDUP(RAND()*26, 0)-1+65), CHAR(ROUNDUP(RAND()*26, 0)-1+97))


Random dates

Excel uses numbers as dates, called 1900-system. The earliest date you can use is 1900-01-01 and it is represented by number 1. 2012-01-01 is 40909 and is also 40909 days later from the date 1900-01-01.

Now we know how dates in excel work, let´s say you want to create a random number between 2012-01-01 and 2012-12-31. 2012-01-01 is 40909 and 2012-12-31 is 41274. 41274 - 40909 = 365 days. Time to construct the formula.

Formula in cell A7:

=40909+ROUNDUP(RAND()*366,0)-1

Random time values



Random hours, minutes and seconds

Formula in cell B3:

=RAND()

Cell B3 is formatted as time.

Random hours

Formula in cell B4:

=(ROUNDUP(B3*24,0)-1)/24

Random minutes

Formula in cell B5:

=(ROUNDUP(RAND()*60,0)-1)/(60*24)

Random hours and minutes

Formula in cell B6:

=(ROUNDUP(B3*60*24,0)-1)/(24*60)

Random minutes and seconds

Formula in cell B7:

=RAND()*(1/24)

Download excel *.xlsx file

Random values.xlsx