0% found this document useful (0 votes)
10 views29 pages

5 Ways To Create Random Numbers in Google Sheets - Ok Sheets

Uploaded by

Thyda Saing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views29 pages

5 Ways To Create Random Numbers in Google Sheets - Ok Sheets

Uploaded by

Thyda Saing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets

5 Ways to Create Random


Numbers in Google Sheets

Do you need to generate random numbers in Google 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.

Ad I’m going to showOPPO A16different


you five $179 methods that will help make generating x
random numbers easier than ever before. OPEN

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

Download Example Files

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.

Generate Random Numbers with the RAND


Function
The first method to look at when creating random numbers is the RAND
function.

It’s a simple function whose only purpose is to create random numbers.

Syntax for the RAND Function

Ad OPPO A16 $179 x


OPEN

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.

Ad OPPO A16 $179 x


OPEN

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.

Simple Example with the RAND Function

= 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.

Generate Random Numbers Between A and B with


the RAND Function
The RAND function is very useful for creating random numbers between 0 and
Ad 1, but what if you OPPO
want A16
to get numbers between 1 and 3, 1 and 5.5, or -1 and 1?
$179 x
OPEN

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

With a simple formula involving the RAND function, it is possible to generate


random numbers between any two given numbers.

= ( 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.

This is a great way to extend the capabilities of the RAND function!


Ad OPPO A16 $179 x
OPEN

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.

Generate Random Numbers with the


Ad
RANDARRAY Function
OPPO A16 $179 x
OPEN

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

Another function that will generate random numbers is the RANDARRAY x


function.

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.

Syntaxt for the RANDARRAY Function

Ad OPPO A16 $179 x


OPEN

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.

= RANDARRAY ( rows, columns )

rows is the number of rows in the returned array.


columns is the number of columns in the returned array.

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.

Simple Example with the RAND Function

Ad OPPO A16 $179 x


OPEN

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 )

In this example, an array of 4 rows and 3 columns is produced. Each of the 12


resulting cells contains a random number between 0 and 1.

Generate Random Numbers Between A and B with


the RANDARRAY Function
The RANDARRAY function is limited like the RAND function and only allows you
to return numbers between 0 and 1.

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

Since the RANDARRAY function is uniformly distributed across 0 and 1, the


formula above will produce uniformly distributed random numbers across N and
M.

= 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.

There is also a function to generate random integer numbers.

Syntaxt for the RANDBETWEEN Function

The RANDBETWEEN function allows you to generate a random integer


Ad number betweenOPPO A16given
any two $179 numbers. x
OPEN

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

= RANDBETWEEN ( minimum, maximum )

minimum is the lower bound of the random number to return.


maximum is the upper bound of the random number to return.

Notes
The RANDBETWEEN function can return values equal to the minimum or
maximum.

The RANDBETWEEN function returns random values that are uniformly


distributed, so any single number between the upper and lower bounds is
equally likely to be returned.

The RANDBETWEEN function is volatile and will recaculate and return new
values when you edit your spreadsheet.

Simple Example with the RANDBETWEEN


Function

Ad OPPO A16 $179 x


OPEN

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.

Generate Random Numbers with Apps


Scripts
Another interesting way to generate random numbers is by using Apps Scripts!

Ad OPPO A16 $179 x


OPEN

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.

Ad OPPO A16 $179 x


OPEN

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

The above code has two function. x

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 output will be similar to the RANDARRAY function, as it produces uniformly


distributed decimal numbers between 0 and 1.

The random numbers inserted into the workbook are values and not formulas
though, so won’t change when you edit your workbook.

You can then run this script from the menu.

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.

Ad OPPO A16 $179 x


OPEN

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.

Generate Random Numbers with an Add-On


The last method for creating random numbers is to use an add-on.

Add-ons are third-party software that can extend the features available in
Google Sheets.

There is even an add-in by Ablebits that is specifically for generating random


numbers and it comes with many more options than the methods mentioned
above.
Ad OPPO A16 $179 x
You will be able to use this add-on for the following. OPEN

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.

To install this add-on follow these steps.

Go to the Add-ons menu and click on Get add-ons from the options.

Ad OPPO A16 $179 x


OPEN

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.

Click on Individual install to install the add-on.

Ad OPPO A16 $179 x

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

1. Go to the Add-ons menu.


2. Select Random Generator from the options.
3. Select Start from the submenu.

Ad OPPO A16 $179 x


OPEN

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

Google provides three functions for random numbers. The RAND, x


RANDARRAY, and RANDBETWEEN functions can all produce uniformly
distributed random numbers.

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!

About the Author


Ad OPPO A16 $179 x
OPEN

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

MultiBank Group™ Open


report this ad

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

Ad OPPO A16 $179 x


OPEN

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

Ad OPPO A16 $179 x


OPEN

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

OPPO Cambodia Open

report this ad

Related Articles

2 Ways to Color Cells in Google Sheets


Ad
May 17, 2022
OPPO A16 $179 x
This post is going to show you step-by-step how to change the color of a cell in GoogleOPEN
Sheets.
Have you ever come...
https://www.oksheets.com/random-numbers/ 25/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets

READ MORE x

4 Ways to Multiply Values in Google Sheets


May 16, 2022
This post is going to show you all the ways you can multiply values in Google Sheets. Basic
arithmetic operations like...
READ MORE

Ad OPPO A16 $179 x


OPEN

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

6 Ways to Show Zero as Blank in Google Sheets


May 9, 2022
This post is going to show you all the ways you can format zero values as blanks in Google
Sheets. Formatting zero...
READ MORE

« Older Entries

Comments

0 Comments

Ad OPPO A16 $179 x

Get the Latest Google Sheets Tips OPEN


https://www.oksheets.com/random-numbers/ 27/29
5/19/22, 10:57 AM 5 Ways to Create Random Numbers in Google Sheets | Ok Sheets

Write For Us
Are you a tech enthusiast with a talent for writing great content? Come write for us!

Find Out More

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

Ad OPPO A16 $179 x


Follow Us
OPEN

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

Ad OPPO A16 $179 x


OPEN

https://www.oksheets.com/random-numbers/ 29/29

You might also like