Random numbers!

alexjmatthews

New Member
Joined
Jan 27, 2003
Messages
7
Could someone post how to get excel to randomly select one of the following times:

08:00
00:00
02:05
04:00
12:00
14:00
16:00
18:00
20:00

Cheers for your help!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Gates Is Antichrist

Well-known Member
Joined
Aug 15, 2002
Messages
1,961
If your data begins in A1, and there is no other data in column A, =OFFSET(A1,ROUND((COUNT(A:A)-1)*RAND(),0),)
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
If you have the Analysis Toolpak installed, perhaps:

=INDEX(A:A,RANDBETWEEN(1,COUNT(A:A)))

or possibly:
=INDEX(A:A,INT(RAND()*COUNT(A:A)+1))
 

Gates Is Antichrist

Well-known Member
Joined
Aug 15, 2002
Messages
1,961

ADVERTISEMENT

Why would one use INDEX instead of OFFSET? One-based logic is feeb! Offset is zero based - like God intended! o_O

I acknowledge that, if I'm not mistaken, there an overwhelming preference for INDEX throughout the lands; God himself would lash forth with a syntax error if anyone ever deviated from the popular solution (index(match... . So everyone does it, except me. What am I missing here?! :unsure:
 

barry houdini

MrExcel MVP
Joined
Mar 23, 2005
Messages
20,825
Why would one use INDEX instead of OFFSET?

For me, I prefer INDEX because it's not a volatile function like OFFSET

Note: the formula

=OFFSET(A1,ROUND((COUNT(A:A)-1)*RAND(),0),)

won't give an even distribution, you'll get less instances of the first and last times in the column
 

Gates Is Antichrist

Well-known Member
Joined
Aug 15, 2002
Messages
1,961

ADVERTISEMENT

For me, I prefer INDEX because it's not a volatile function like OFFSET
Granted. That may be persuasive enough.
 

Gates Is Antichrist

Well-known Member
Joined
Aug 15, 2002
Messages
1,961
Note: the formula

=OFFSET(A1,ROUND((COUNT(A:A)-1)*RAND(),0),)

won't give an even distribution, you'll get less instances of the first and last times in the column
Oops! Got me there! /self-brain-pummel-with-hammer mode on.
 

Watch MrExcel Video

Forum statistics

Threads
1,133,466
Messages
5,658,952
Members
418,478
Latest member
Adam19931

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top