Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel Generate Random Time: 3 Easy Ways

· 5 min read · Home Tech

In this article
  1. Formula
  2. Worked Example
  3. How to Enter the Formula in Excel
  4. Making the Random Time Static
  5. Generating a List of Random Times
  6. Common Mistakes and Misconceptions
  7. Alternatives: RANDARRAY and VBA
  8. Frequently Asked Questions

You can generate random times in Excel using the RAND() function combined with simple arithmetic: =RAND() gives a random decimal between 0 and 1, which represents a fraction of a 24-hour day, so =RAND()*24 returns a random time as a decimal number of hours. Format the cell as a time (e.g., HH:MM) and you get a random time between 00:00 and 23:59. This article explains the formulas, how to control the range, how to make the times static, and common pitfalls.

in t | Start hour | hour | 9 | 0
in d | Duration (hours) | h | 8 | 0
out rand_time | Random time (decimal hours) | h | t + RAND()*d | 2

Formula

The core formula is:

Random time = Start + RAND() × Duration

Where:

  • Start – the earliest time (in hours after midnight) you want to allow. For 9:00 AM, Start = 9.
  • Duration – the length of the time window in hours. For a window from 9:00 AM to 5:00 PM, Duration = 8.
  • RAND() – Excel’s built-in function that returns a random decimal ≥ 0 and < 1.

The result is a decimal number of hours (e.g., 11.75 = 11:45 AM). To display it as a time, format the cell with a time format like HH:MM or HH:MM:SS.

Worked Example

Using the default values from the calculator above (Start = 9, Duration = 8):

  1. Excel generates a random decimal, say 0.625.
  2. Multiply: 0.625 × 8 = 5.
  3. Add the start: 9 + 5 = 14.
  4. 14 hours after midnight is 2:00 PM.

If RAND() returns 0.1, the result is 9 + 0.8 = 9.8 → 9:48 AM. If RAND() returns 0.99, the result is 9 + 7.92 = 16.92 → 4:55 PM. The formula always stays within the 9-to-5 window.

How to Enter the Formula in Excel

To get a random time in a cell:

  1. Select the cell where you want the time.
  2. Type =RAND() and press Enter. You’ll see a decimal like 0.4521.
  3. To convert that to a time between 00:00 and 23:59, format the cell: right-click → Format Cells → Time → select a format like 1:30 PM or 13:30.
  4. To get a time within a specific range, use =RAND()*(end-start)+start, where start and end are Excel time values. For example, to get a time between 9:00 AM and 5:00 PM: =RAND()*(TIME(17,0,0)-TIME(9,0,0))+TIME(9,0,0).

The TIME function converts hours, minutes, seconds into an Excel time value (a fraction of a day). You can also use decimal hours directly: =RAND()*8+9 and format as time.

Making the Random Time Static

RAND() recalculates every time the worksheet changes or you press F9. If you need a fixed random time that doesn’t change, you have two options:

  • Copy and paste as values: After generating the times, copy the cells, right-click, and choose Paste Special → Values. This replaces formulas with static numbers.
  • Use a keyboard shortcut: In many Excel versions, pressing F9 recalculates all formulas. To keep the current value, immediately copy and paste as values.

If you want a random time that updates only when you explicitly recalculate, set calculation to manual (Formulas → Calculation Options → Manual) and press F9 when you want new times.

Generating a List of Random Times

To create many random times at once:

  1. Enter the formula in the first cell of a column.
  2. Drag the fill handle down to fill as many cells as you need.
  3. Each cell will show a different random time.

For example, to generate 10 random times between 8:00 AM and 8:00 PM, enter =RAND()*12+8 in cell A1, then drag down to A10. Format the range as a time.

Common Mistakes and Misconceptions

One frequent error is forgetting that Excel times are fractions of a day. If you enter =RAND()*24 and format as time, you get a random time correctly. But if you enter =RAND()*24 and expect a number like 15.5, you need to format as a number, not a time.

Another mistake is using RANDBETWEEN with time values. RANDBETWEEN only works with integers, so =RANDBETWEEN(TIME(9,0,0),TIME(17,0,0)) will return a #VALUE! error. Use RAND() instead.

Also, remember that RAND() is volatile – it recalculates on every change. If you want a stable set of times, convert to values as described above.

Alternatives: RANDARRAY and VBA

In Excel 365 and Excel 2021, you can use the RANDARRAY function to generate an array of random decimals at once. For example, =RANDARRAY(10,1,9,17,TRUE) returns 10 random times (as decimal hours) between 9 and 17 (i.e., 9:00 AM to 5:00 PM). The TRUE argument means integer values are not required (so you get fractional hours).

For more control, you can use a VBA macro, but that requires the Developer tab and is overkill for most users. The RAND() formula is simpler and works in all Excel versions.

Frequently Asked Questions

How do I generate a random time between two specific times?

Use the formula =RAND()*(end_time - start_time) + start_time, where start_time and end_time are Excel time values. For example, =RAND()*(TIME(17,0,0)-TIME(9,0,0))+TIME(9,0,0) gives a random time between 9:00 AM and 5:00 PM.

Why does my random time change every time I edit a cell?

Because RAND() is a volatile function – it recalculates whenever the worksheet recalculates. To prevent this, copy the cells and paste as values (Paste Special → Values).

Can I generate random times with seconds?

Yes. The RAND() function gives a decimal with many digits, so when formatted as HH:MM:SS, you get random seconds as well. For example, =RAND()*24 formatted as HH:MM:SS will show times like 14:23:45.

How do I generate a random time in a specific hour, like only between 10:00 and 10:59?

Set the start to 10 and the duration to 1: =RAND()*1+10. Format as time and you’ll get a random time between 10:00 and 10:59.

Does RAND() include the end of the range?

No. RAND() returns a value greater than or equal to 0 and less than 1. So the random time will be ≥ start and < start + duration. For example, with start=9 and duration=8, the result is ≥ 9:00 and < 17:00, never exactly 17:00.

Can I generate a random date and time together?

Yes. Use =RAND()* (end_date - start_date) + start_date where start_date and end_date are full date-time values. Format the cell as a custom format like dd/mm/yyyy hh:mm.