Generate 2 Random Numbers: How to Do It

How-to basics · Updated November 23, 2026

The simplest way to generate 2 random numbers is to use a random number generator (RNG) tool or a programming language’s built-in function, such as Math.random() in JavaScript or RAND() in Excel. For example, in Excel, entering =RANDBETWEEN(1,100) in two cells gives you two independent random integers between 1 and 100. Below, we explain the methods, the math behind them, and how to choose the right approach for your needs.

Why Generate Two Random Numbers?

Generating two random numbers is a common task in many fields, from simple games and contests to scientific sampling and cryptography. You might need two numbers for a lottery draw, a dice roll (two dice), a coordinate pair (x, y), or a statistical sample. The key is that the two numbers should be independent—the value of the first should not affect the second—unless you specifically want them to be distinct or ordered.

How Random Number Generators Work

Random number generators come in two main types: true random and pseudo-random. True random generators use physical processes, like atmospheric noise or radioactive decay, to produce numbers that are unpredictable. Pseudo-random generators use mathematical algorithms to produce sequences that appear random but are actually deterministic, starting from a seed value. Most software, including Excel and JavaScript, uses pseudo-random generators because they are fast and reproducible (if you set a seed).

For most everyday uses, pseudo-random is sufficient. However, for security-sensitive applications like encryption, you should use a cryptographically secure generator, such as crypto.getRandomValues() in browsers or the secrets module in Python.

How to Generate Two Random Numbers in Excel

In Microsoft Excel (Microsoft 365 on Windows), the simplest way is to use the RANDBETWEEN function. It returns a random integer between a lower and upper bound (inclusive).

  • Type =RANDBETWEEN(1,100) in cell A1 and press Enter.
  • Type the same formula in cell A2 (or copy A1 to A2).

Each cell will show a different random integer between 1 and 100. If you want decimal numbers, use =RAND() which returns a number between 0 and 1. To get decimals in a range, use =RAND()*(max-min)+min. For example, =RAND()*100 gives a number between 0 and 100.

Note: These formulas recalculate every time the worksheet changes. To freeze the values, copy the cells and paste as values (right-click > Paste Special > Values). On Mac, the process is the same; the ribbon paths are identical.

Generating Two Random Numbers in Programming Languages

If you are coding, here are common ways to generate two random numbers:

  • JavaScript: Math.random() returns a decimal between 0 (inclusive) and 1 (exclusive). To get an integer between 1 and 100, use Math.floor(Math.random()*100)+1. Call it twice to get two numbers.
  • Python: Use the random module: random.randint(1,100) returns an integer. Call it twice.
  • R: sample(1:100, 2) returns two distinct integers from 1 to 100.

For cryptographically secure random numbers in JavaScript, use crypto.getRandomValues(new Uint32Array(2)) to get two 32-bit unsigned integers.

How to Choose the Right Method

Your choice depends on your context:

  • Casual use (games, contests): Any pseudo-random generator works. Use Excel or a simple online tool.
  • Statistical sampling: Use a generator that allows a seed for reproducibility. In R, set set.seed(123) before sampling.
  • Security (passwords, tokens): Use a cryptographically secure generator. In Python, use secrets.randbelow(100).
  • Distinct numbers: If the two numbers must be different (e.g., for a raffle), use sample(1:100, 2) in R or a loop in other languages.

Common Problems and Misconceptions

One common misconception is that RAND() in Excel generates truly random numbers—it does not; it is pseudo-random. Another issue is that if you use =RANDBETWEEN(1,100) in two cells, they might occasionally be the same. If you need distinct numbers, you must explicitly check and regenerate.

Another problem: many people think that random numbers are evenly distributed in a small sample. With only two numbers, you might get 5 and 5, which looks non-random, but it is possible. True randomness does not guarantee uniqueness or uniformity in small samples.

Alternatives to Generating Random Numbers

If you do not have access to a computer, you can use physical methods:

  • Roll two dice for numbers 1–6 each.
  • Draw numbered balls from a hat.
  • Use a random number table from a statistics book.

These methods are truly random (assuming fair dice) but less convenient for large ranges. For a range like 1–100, you could use two ten-sided dice (one for tens, one for ones).

Frequently Asked Questions

How do I generate two random numbers that are not equal?

In Excel, you can use a formula like =IF(A1=A2, RANDBETWEEN(1,100), A2) but that is not reliable. Better: generate the first number in A1, then in A2 use =RANDBETWEEN(1,99) and adjust if it is >= A1. In Python, use random.sample(range(1,101), 2) to get two distinct numbers.

Can I generate two random numbers without repeats in a sequence?

Yes, if you need a sequence of two distinct numbers, use sampling without replacement. In R, sample(1:100, 2, replace=FALSE) does that. In Excel, you would need a more complex approach, such as using a helper column with RAND() and then ranking.

What is the difference between RAND() and RANDBETWEEN() in Excel?

RAND() returns a decimal between 0 and 1 (inclusive of 0, exclusive of 1). RANDBETWEEN(bottom, top) returns an integer between the two specified numbers, inclusive. Use RAND() when you need a continuous value, and RANDBETWEEN for integers.

Are the numbers from Excel truly random?

No, they are pseudo-random. Excel uses a linear congruential generator, which is good enough for most non-security purposes, but not for cryptography. For security, use dedicated tools.

How can I generate two random numbers in Google Sheets?

Google Sheets uses the same functions: =RANDBETWEEN(1,100) works identically. The difference is that Google Sheets recalculates less frequently (on change, not every recalculation). You can also use =RANDARRAY(2,1,1,100,TRUE) to get two random integers in a column.

Can I generate two random numbers that sum to a specific value?

Yes, but it requires a method. For example, to get two numbers that sum to 100, generate the first as =RANDBETWEEN(1,99) and set the second as =100-A1. This ensures the sum but makes the second number dependent on the first.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.