Random Number 0-9: How to Generate Them

How-to basics · Updated November 22, 2026

Yes, you can randomly generate numbers from 0 to 9 using a simple formula in any spreadsheet program: in Excel, enter =RANDBETWEEN(0,9) in a cell and press Enter. This returns a whole number between 0 and 9, inclusive, and recalculates each time the sheet changes. For a static result that doesn’t update, copy the cell and paste it as a value (right-click > Paste Special > Values).

Why You’d Want Random Digits

Random numbers from 0–9 aren’t just for dice games or classroom exercises. They appear in real tasks like:

  • Creating a random PIN or password digit (though for security, use a dedicated password manager instead of a spreadsheet).
  • Simulating a single digit of a lottery draw or a simple slot machine for a game.
  • Selecting a random item from a list of 10 options (add 1 to the result to get 1–10).
  • Testing data entry or quality checks by generating random test values.

Because the range is small, the output is easy to verify and use in larger formulas.

How RANDBETWEEN Works

The RANDBETWEEN(bottom, top) function takes two arguments: the lowest and highest integers you want. For 0–9, you write =RANDBETWEEN(0,9). Excel’s calculation engine produces a pseudo-random integer in that closed interval. “Pseudo-random” means it’s generated by an algorithm, not true atmospheric noise, but for most spreadsheet purposes it’s statistically uniform—each digit appears with roughly equal frequency over many trials.

Every time Excel recalculates (for example, when you edit any cell, press F9, or open the file), the formula produces a new number. If you need many digits at once, enter the formula in a cell and drag the fill handle down or across to fill a range. Each cell gets its own independent random value.

For a decimal between 0 and 1, use =RAND() instead. To get a random digit from that, you could use =INT(RAND()*10), but RANDBETWEEN is simpler and clearer.

Making the Result Static

A common frustration is that the numbers keep changing. If you need a fixed set of digits—say, for a report or a draw—you have to freeze them. The easiest way:

  1. Select the cells containing the formulas.
  2. Press Ctrl+C (Mac: Cmd+C) to copy.
  3. Right-click the same selection, choose Paste Special > Values (or use Ctrl+Shift+V in Excel 365).

This replaces the formulas with the current numbers, so they never change again. Alternatively, you can enable manual calculation mode (Formulas > Calculation Options > Manual) and press F9 only when you want new digits—but then you must remember to recalculate before using the results.

Generating a Whole List of Digits

To fill a column with 100 random digits, type =RANDBETWEEN(0,9) in A1, then double-click the fill handle (the small square at the bottom-right of the cell) to fill down as far as you need. If you want the digits in a single cell as a string (like “483920”), you can combine them with =TEXTJOIN("",TRUE,RANDBETWEEN(0,9),RANDBETWEEN(0,9),...)—but that’s tedious for long strings. A better approach is to generate digits in separate cells, then use =TEXTJOIN("",TRUE,A1:A10) to concatenate them.

For a random number with a specific number of digits (e.g., a 6-digit code), you can use =RANDBETWEEN(100000,999999) directly, which avoids leading zeros. If leading zeros are allowed, you’d need the TEXT function to format them: =TEXT(RANDBETWEEN(0,999999),"000000").

Common Problems and Fixes

  • The number includes 10 or -1: Check your arguments. RANDBETWEEN(0,9) only gives 0 through 9. If you see other values, you likely typed a different range.
  • All cells show the same number: That happens if you entered the formula as an array or if calculation is set to manual and you haven’t recalculated. Press F9 to force recalculation.
  • The result is a decimal like 4.7: You probably used =RAND()*9 instead of RANDBETWEEN. RAND returns a decimal; multiply and round if needed.
  • Numbers change when I don’t want them to: As described above, paste as values or switch to manual calculation.
  • Mac vs. Windows: The function works identically on both. The keyboard shortcuts differ (Ctrl vs. Cmd), but the formula is the same.

Alternatives to RANDBETWEEN

If you don’t want formulas, you can use Excel’s built-in random generator via Data > Data Analysis > Random Number Generation (you may need to enable the Analysis ToolPak). This lets you specify a distribution, number of variables, and output range, but it’s overkill for a simple digit.

For a more controlled approach, you can use =RANDARRAY(10,1,0,9,TRUE) in Excel 365 to generate 10 rows of integers from 0 to 9 in one step. The arguments are: number of rows, columns, min, max, and whether to return integers (TRUE). This is a dynamic array formula—it spills into adjacent cells automatically.

If you’re in Google Sheets, the function is the same: =RANDBETWEEN(0,9). Google Sheets also has =RANDARRAY() but with slightly different syntax—check the help for your version.

Is It Truly Random?

Excel’s random number generator is not cryptographically secure. It’s based on a pseudo-random algorithm that is fine for simulations, games, or sampling, but not for security-sensitive applications like generating encryption keys or lottery draws that determine real money. For that, use a dedicated random number generator from a trusted source, or a hardware-based generator. Also, note that the sequence repeats after a very long cycle, but you’ll never hit that in normal use.

For a quick test of uniformity, generate 1,000 digits and count how many times each appears. With a good generator, each digit should appear roughly 100 times, give or take a few. This is a useful sanity check if you’re relying on the results.

Frequently Asked Questions

How do I generate a random number between 0 and 9 without repeats?

RANDBETWEEN can produce repeats, as it should for independent random digits. If you need a permutation of 0–9 (each digit exactly once), use =SORTBY(SEQUENCE(10,1,0,1),RANDARRAY(10)) in Excel 365. This creates a sequence 0–9 and sorts it by random values, giving a shuffled list with no repeats.

Can I generate a random digit that doesn’t change when I open the file?

Yes. After generating the numbers, copy the cells and paste as values (right-click > Paste Special > Values). The numbers become static text. Alternatively, set calculation to manual and only recalculate when you want new digits, but then the file will show the last calculated values when opened.

What’s the difference between RAND and RANDBETWEEN?

RAND() returns a decimal between 0 and 1, like 0.4832. RANDBETWEEN(bottom, top) returns a whole number between the two integers you specify. To get a digit, use RANDBETWEEN(0,9). If you only have RAND, you could use =INT(RAND()*10), but RANDBETWEEN is clearer.

Why does my random number change every time I type something in another cell?

That’s normal. Excel recalculates all volatile functions (RAND and RANDBETWEEN) whenever any cell changes. If you want to prevent that, switch to manual calculation (Formulas > Calculation Options > Manual) or paste the results as values.

Is there a way to generate a random digit in a specific cell without affecting others?

No, because the function is volatile. But you can copy that cell and paste as value to freeze it, then delete the formula. Or, if you only want one random digit per sheet, just use one formula and then paste as value.

Can I use this for a lottery or gambling?

Technically yes, but Excel’s generator is not suitable for any application where fairness or security is legally required. For a real lottery, you need a certified random number generator. For a casual game among friends, it’s fine.

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.