Selecting Ten Random Numbers

Written by Allen Wyatt (last updated October 18, 2025)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365


3

Fawn needs a way to select 10 whole numbers from a pool of 150 potential numbers. For instance, if the pool contains the sequential whole numbers of 201 through 350, she needs to select 10 numbers from that pool, at random.

The traditional way to do this is to use a very simple function in a cell, like this:

=RANDBETWEEN(201,350)

This returns a single random value between 201 and 350, inclusive. Copy the formula down for 9 more cells, and you end up with the 10 desired random values. The problem, though, is that you could end up with duplicate values. This is especially true if the pool of potential numbers is reduced in size and the number of desired values increases.

Continuing down the traditional path, this potential of duplication is reduced significantly by using the RAND function instead of RANDBETWEEN. This is because RAND returns a value greater than or equal to 0 and less than 1, at a precious of 15 decimal places. Thus, you could use the following formula in a cell to return a number in the range of 201 to 350:

=INT(RAND()*150)+201

Copy this down to 9 more cells, and you end up with your 10 desired values, with virtually zero chance of duplication.

With the advent of the newest dynamic array functions, the approach can be simplified quite a bit. Consider the following formula:

=RANDARRAY(10,1,201,350,1)

This returns 10 integer values between 201 and 250. The problem here is the same as it is with RANDBETWEEN—there could easily be duplicates. Some suggest that you can remove the problem by enclosing the function within the UNIQUE function:

=UNIQUE(RANDARRAY(10,1,201,350,1))

This does ensure that no duplicates are returned, but you are no longer guaranteed to always have 10 values, which goes against what Fawn needs.

The best solution is to not force RANDARRAY to use integer values. If you allow it to work with decimal values, it acts very much like the RAND function, returning an array of values between 0 and 1. To see how powerful this can be, consider the following formula:

=TAKE(SORTBY(SEQUENCE(150,1,201),RANDARRAY(150)),10)

The SEQUENCE function returns an array of values 201 through 350 and the RANDARRAY function returns an array of 150 random values between 0 and 1. The SORTBY function is then used to sort the integer sequence by the results of the random array. Finally, the TAKE function returns the first 10 values from the sorted array. The result is always 10 values, always in random order, with absolutely no chance of duplicates.

The SEQUENCE, SORTBY, RANDARRAY, and UNIQUE functions are available in Excel 2021 and 2024. To use the TAKE function you will need Excel 2024. All of these functions are available to users of Microsoft 365.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2319) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Repeating the First Column of a Table

Need the first column of a table to be repeated on multiple pages? You can't do it automatically in Word, but you can use ...

Discover More

Jumping to a Section

One way you can navigate through a document is to jump from section to section. Here's the traditional way to quickly get ...

Discover More

Taskbar Setting isn't Sticky

Understanding how Excel sets the taskbars upon opening.

Discover More

Dive Deep into Macros! Make Excel do things you thought were impossible, discover techniques you won't find anywhere else, and create powerful automated reports. Bill Jelen and Tracy Syrstad help you instantly visualize information to make it actionable. You’ll find step-by-step instructions, real-world case studies, and 50 workbooks packed with examples and solutions. Check out Microsoft Excel 2019 VBA and Macros today!

More ExcelTips (ribbon)

Inserting Dashes between Letters and Numbers

If you need to add dashes between letters and numbers in a string, the work can quickly get tedious. This tip examines ...

Discover More

Finding the Directory Name

Need to know the directory (folder) in which a workbook was saved? You can create a formula that will return this ...

Discover More

Counting Unique Values

Need to know a count of unique values in a range of cells? There are a couple of ways you can tackle the problem.

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 3?

2025-10-21 02:13:07

fred potter

What about using VBA:

Sub UniqueRandomNumbers()
'Original idea was from Wellsr.com
'I modified it to play with Lotto numbers, (didn't do me any good)
'but for this exercise, maybe it could work

Dim lowLimit As Long, highLimit As Long, numCount As Long
Dim dict As Object, arr() As Variant, i As Long, j As Long, temp As Variant
Dim r As Long

' Sheet Layout:
' A3 = Lower limit
' B3 = Upper limit
' C3 = Number of randoms
' E3 = Random number output

lowLimit = Range("A3").Value
highLimit = Range("B3").Value
numCount = Range("C3").Value

If numCount > (highLimit - lowLimit + 1) Then
MsgBox "Not enough unique numbers in range!", vbExclamation
Exit Sub
End If

Set dict = CreateObject("Scripting.Dictionary")

' Seed random number generator with system clock
Randomize

' Generate unique random numbers
Do While dict.Count < numCount
r = Int((highLimit - lowLimit + 1) * Rnd + lowLimit)
dict(r) = 1
Loop

' Transfer dictionary keys to array
arr = dict.Keys

' Sort ascending
For i = LBound(arr) To UBound(arr) - 1
For j = i + 1 To UBound(arr)
If arr(i) > arr(j) Then
temp = arr(i)
arr(i) = arr(j)
arr(j) = temp
End If
Next j
Next i

' Clear old results
Range("E3").Resize(1000, 1).ClearContents

' Output of unique randoms
Range("E3").Resize(numCount, 1).Value = Application.Transpose(arr)

End Sub


2025-10-20 11:38:25

Dave Bonin

I never liked using Excel's random number generators. Two reasons:

1) The functions are computationally intensive, making them very slow if you need a lot of random numbers, such as for a Monte Carlo simulation.

2) They recalculate with every refresh, which makes debugging and verification difficult.

Instead, I like to copy and paste values from a table called "A Million Random Digits with 100,000 Normal Deviates." It was published by the Rand Corporation in the 1955. It's available online for free.

This table has been thoroughly vetted. Just pick a random spot and copy as many values as needed. You will get random numbers that won't change with every recalculation.


2025-10-18 10:44:59

Mike J

Allen's comment about the second formula is a bit mystifying. Using the RAND() function may well give 15 digits of precision, but by the time the result has been multiplied by 150 and then truncated by the INT() function to just 3 significant digits, you have just as much chance of returning duplicates as the previous formula.

If truly random numbers need to be generated, Excel is probably not the generator of choice.
Online random number generators are probably better, e.g. random.org/integers has a simple interface that serves this purpose extremely well and has an API that could be used (by someone more experienced than I) to produce the desired output automatically.

But even truly random numbers may well still produce duplicates.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.