5 Ways To Create Random Numbers in Google Sheets - Ok Sheets
5 Ways To Create Random Numbers in Google Sheets - Ok Sheets
They can be a great way to create sample data or they might even be essential
to some statistical methods.
The good news is, there are several easy ways to generate random numbers in
Google Sheets.
https://www.oksheets.com/random-numbers/ 1/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
1. RAND function x
2. RANDBETWEEN function
3. RANDARRAY function
4. Apps Scripts
5. Third party Add-ons
Read on to find out just how simple it is with this step-by-step guide! Make sure
you get the example workbook to follow along.
https://www.oksheets.com/random-numbers/ 2/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
RAND ( )
The RAND function takes no argument inputs and returns a random number
between 0 and 1.
Notes
The number returned will be a decimal number greater than 0 and less than 1. It
will never return 0 or 1 as a result.
Numbers that are returned follow a uniform distribution. This means that every
number between 0 and 1 is equally likely to occur in the results.
https://www.oksheets.com/random-numbers/ 3/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
The RAND function is volatile. This means the function will recalculate and a x
new result will be returned every time you make a change in the spreadsheet,
refresh calculations, refresh the browser, or open the spreadsheet.
= RAND ( )
In this example, the RAND function has been entered in cell B3 and copied
down the row.
No arguments are needed and the function returns random decimal numbers
between 0 and 1.
https://www.oksheets.com/random-numbers/ 4/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
✕ x
= ( B - A ) * RAND ( ) + B
The above formula will generate a random decimal number between A and B,
where A and B are any two numbers such that A is less than B.
Since RAND will generate a uniform random distribution across 0 and 1, this
formula will generate a uniform distribution across A and B.
https://www.oksheets.com/random-numbers/ 5/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
= 20 * RAND ( ) - 10
In the example above you can see a set of random numbers generated between
-10 and 10.
https://www.oksheets.com/random-numbers/ 6/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
The RANDARRAY function is nearly the exact same as the RAND function but
has one key difference.
While the RAND function returns a single random number, the RANDARRAY
function can be used to return an array of random numbers.
https://www.oksheets.com/random-numbers/ 7/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
The RANDARRAY function will return an array of random values. Each value in x
the returned array will be between 0 and 1.
Notes
If you omit the row and column index arguments from the RANDARRAY
function, they will default to 1.
RANDARRAY is a volatile function and will recalculate and return a new array of
values any time the spreadsheet is changed.
The values returned will follow a uniform distribution over 0 and 1, where any
single value is equally likely to occur.
https://www.oksheets.com/random-numbers/ 8/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
= RANDARRAY ( 4, 3 )
This can also be extended with a simple formula in order to generate an array of
random numbers between any two given numbers A and B.
= ARRAYFORMULA( ( B - A ) * RANDARRAY ( N, M ) + B )
The above formula will generate an array of random numbers between A and B
with N rows and M columns.
Ad OPPO A16 $179 x
OPEN
https://www.oksheets.com/random-numbers/ 9/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
✕ x
= ARRAYFORMULA( 15 * RANDARRAY ( 4, 3 ) + 5 )
For example, the above formula will produce an array of 4 rows and 3 columns.
Each of the numbers in the resulting array will be a random number between -10
and 5.
Ad
Generate OPPO
Random
A16 $179 Numbers with the x
OPEN
RANDBETWEEN Function
https://www.oksheets.com/random-numbers/ 10/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
So far, you have seen a way to generate decimal random numbers using x
functions.
https://www.oksheets.com/random-numbers/ 11/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
Notes
The RANDBETWEEN function can return values equal to the minimum or
maximum.
The RANDBETWEEN function is volatile and will recaculate and return new
values when you edit your spreadsheet.
https://www.oksheets.com/random-numbers/ 12/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
= RANDBETWEEN ( -10, 5 )
In this example, a single random integer value between -10 and 5 is returned.
https://www.oksheets.com/random-numbers/ 13/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
Check out this beginner’s guide to Apps Scripts for the complete run-down on x
how to use this tool.
Apps Scripts use the JavaScript programming language so you can leverage
various JavaScript functions such as Math.random() to create a set of random
numbers.
This is great if you want to create a set of static random numbers that don’t
change when you update your workbook. The previous methods all used volatile
functions that recalculate every time you update your workbook.
Go to the Tools menu and select the Script editor option to open the script
editor.
Paste the below code into the script editor and save the script.
https://www.oksheets.com/random-numbers/ 14/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
function fillRandom() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveRange();
for (var col = 1; col <= range.getWidth(); col++) {
for (var row = 1; row <= range.getHeight(); row++) {
range.getCell(row, col).setValue(Math.random());
}
}
};
function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "Fill",
functionName : "fillRandom"
}];
sheet.addMenu("Random", entries);
};
Ad OPPO A16 $179 x
OPEN
https://www.oksheets.com/random-numbers/ 15/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
fillRandom will fill each cell in the active range with a randomly generated
number using the Math.random() function.
onOpen will create a new menu in the UI which will allow you to run the
fillRandom function.
The random numbers inserted into the workbook are values and not formulas
though, so won’t change when you edit your workbook.
1. Select a range of cells which you want to fill with random values.
2. Go to the Random menu.
3. Click on Fill.
This will run the script. The first time it runs you will need to give it the required
permission to run.
https://www.oksheets.com/random-numbers/ 16/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
The selected range will then get filled with random numbers between 0 and 1.
These are values and not formulas, so they will remain unchanged when you
edit your spreadsheet.
Add-ons are third-party software that can extend the features available in
Google Sheets.
https://www.oksheets.com/random-numbers/ 17/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
Generate integer or decimal random numbers with lower and upper bounds.
Generate unique values without repeats.
Genrate random dates.
Generate values from a custom list like a set of products from your company.
Generate random text strings for passwords.
Go to the Add-ons menu and click on Get add-ons from the options.
https://www.oksheets.com/random-numbers/ 18/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
Search for Random Generator in the search bar and choose the Random
Generator add-on by Ablebits from the resulting search options.
Now you will be able to use this add-on from the Add-ons menu. OPEN
https://www.oksheets.com/random-numbers/ 19/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
https://www.oksheets.com/random-numbers/ 20/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
This will open up the Random Generator menu on the right side of the screen
where you’ll find many options for generating random integers, decimals,
Booleans, dates, custom list values, and strings.
Choose your desired options and click on the Generate button. It’s that easy to
generate many different types of random output.
Conclusions
Google Sheets has many options for generating random numbers.
Ad OPPO A16 $179 x
OPEN
https://www.oksheets.com/random-numbers/ 21/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
If you’re looking to produce a set of static random numbers, you can also use
Apps Scripts to fill a range with random numbers which won’t change.
You can even install an add-in for many more options to generate random
numbers.
Hopefully, this post helps you with your random number needs. Let me know in
the comments below!
https://www.oksheets.com/random-numbers/ 22/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
John MacDougall
John is a Microsoft MVP and freelance consultant and trainer specializing in
Excel, Power BI, Power Automate, Power Apps, and SharePoint. You can find
other interesting articles from John on his blog or YouTube channel.
$40,000 Trading
Deposit Bonus
Top Posts
VLOOKUP and INDEX & MATCH Formulas
The Definitive Guide to the QUERY Function
The Definitive Guide to Data Validation
Everything You Need to Know About Filtering Data
Everything You Need to Know About Sorting Data
The Beginners Guide to Apps Scripts
Everything You Need to Know About Smart Fill
https://www.oksheets.com/random-numbers/ 23/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
x
Ok Sheets
Subscribe and get the latest Google Sheets tips
straight to your inbox!
First Name
Your Email
Sign Up
https://www.oksheets.com/random-numbers/ 24/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
Ad x
OPPO A96 $269
OPPO A95 The Smart Performer
report this ad
Related Articles
READ MORE x
https://www.oksheets.com/random-numbers/ 26/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
« Older Entries
Comments
0 Comments
Write For Us
Are you a tech enthusiast with a talent for writing great content? Come write for us!
Ok Sheets
Subscribe and get the latest Google Sheets tips
straight to your inbox!
First Name
Your Email
Sign Up
Follow Us
Follow us on social media to stay up to date with the latest in Google Sheets!
a
Copyright © 2022 OkSheets. All Rights Reserved.
Designed by John MacDougall | Powered by WordPress
https://www.oksheets.com/random-numbers/ 28/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets
x
This website is not affiliated in any way with Google or Alphabet Inc.
report this ad
https://www.oksheets.com/random-numbers/ 29/29