Can I Generate a Random Number? Yes, Here’s How

How-to basics · Updated November 23, 2026

Yes, you can generate a random number — instantly, for free, and in almost any tool you already have. The real question is what kind of randomness you need: a quick pick for a game, a statistically fair sample for a survey, or a cryptographically secure value for a password. This article covers the practical methods, the math behind them, and how to choose the right one.

What “Random” Actually Means

When people ask for a random number, they usually mean one of two things:

  • Uniform randomness — every number in a range has an equal chance of appearing (like rolling a fair die).
  • Unpredictability — even if you know the method, you can’t guess the next value (like a lottery draw).

These are different. A simple calculator or spreadsheet function gives you the first but not the second. For most everyday uses — picking a winner, shuffling a list, simulating dice — uniform randomness is enough. For passwords, encryption, or gambling, you need cryptographic randomness, which is much harder to fake.

How Computers Generate Random Numbers

Computers are deterministic machines; they follow instructions exactly. So they can’t produce true randomness on their own. Instead, they use two approaches:

  1. Pseudorandom number generators (PRNGs) — algorithms that start with a “seed” (a number) and apply a mathematical formula to produce a long sequence that looks random. The sequence repeats eventually, but the period is so long (often billions of numbers) that it’s practically irrelevant. Excel’s RAND() and most programming languages’ rand() use PRNGs.
  2. Hardware random number generators (HRNGs) — these use physical processes like electronic noise or radioactive decay to generate truly unpredictable values. Your phone and computer’s CPU have built-in HRNG circuits (e.g., Intel’s RDSEED) that feed the operating system’s entropy pool.

When you use a website like random.org, it draws from atmospheric noise — a true random source. When you use Excel or Python’s random module, you get a PRNG seeded by the system’s entropy, which is good enough for most non-security purposes.

Quick Ways to Generate a Random Number Right Now

Here are the most accessible methods, no installation needed:

  • Google search — type “random number” into Google and you’ll get a built-in generator with a range slider.
  • Calculator apps — most phone calculators have a RAND button (often under a shift or function menu) that returns a decimal between 0 and 1.
  • Excel or Google Sheets — use =RANDBETWEEN(1,100) for a whole number between 1 and 100, or =RAND() for a decimal between 0 and 1. In Excel, these recalculate every time the sheet changes; press F9 (Windows) or Cmd+= (Mac) to force a refresh.
  • Command line — on Windows PowerShell, type Get-Random -Minimum 1 -Maximum 101 (returns 1–100). On Mac/Linux terminal, type echo $((RANDOM % 100 + 1)).
  • Dedicated websites — random.org, randomnumbergenerator.com, or even Wolfram Alpha (type “random integer 1 to 100”).

For a single number, any of these works. But if you need many numbers without repeats, you’ll need a different approach (see below).

How to Choose the Right Method

Match the method to your use case:

  • Games, contests, or casual use — a PRNG from Excel or a website is fine. The tiny bias (if any) won’t matter.
  • Statistical sampling or simulations — you need a high-quality PRNG with a long period. Use Python’s random module (Mersenne Twister) or R’s sample(). Avoid Excel’s RAND() for serious Monte Carlo work because its algorithm is older and less robust.
  • Cryptography, passwords, or security tokens — use a cryptographically secure generator. In Python, use secrets module; in JavaScript, use crypto.getRandomValues(); in Excel, you can’t do this natively — use a dedicated tool or an add-in.
  • True randomness — if you want physical randomness (e.g., for a lottery draw that must be auditable), use random.org or a hardware device like a lava lamp (yes, Cloudflare uses them).

For most people, the rule is simple: if you’re not dealing with money or security, any method is fine. If you are, use a cryptographic one.

Common Pitfalls and Misconceptions

People often make these mistakes:

  • Using RAND() in Excel and copying values — if you copy a cell with RAND() and paste it, you get a new random number, not the same one. To keep a fixed value, copy and paste as values (right-click > Paste Special > Values).
  • Assuming RAND() is unpredictable — it’s seeded by the system time, so if you know the seed, you can predict the sequence. Don’t use it for passwords.
  • “Random” doesn’t mean “no repeats” — if you generate 10 numbers between 1 and 10, you might get duplicates. To get a shuffled list of unique numbers, use a permutation: in Excel, sort a list of numbers by a random column; in Python, use random.sample(range(1,11), 10).
  • Seeding a PRNG the same way twice — if you set the seed to a fixed value (e.g., in Python random.seed(42)), you’ll get the same sequence every time. That’s useful for reproducibility in testing, but not for randomness.

Random Number Generation in Spreadsheets (Excel & Google Sheets)

Since this site focuses on spreadsheets, here’s the practical detail:

In Excel for Microsoft 365 (Windows), type =RAND() in any cell to get a decimal between 0 and 1. To get an integer between 1 and 100, use =RANDBETWEEN(1,100). Both recalculate whenever the sheet recalculates (e.g., when you edit any cell or press F9). On Mac, press Cmd+= to force recalculation. In Excel for the web, they recalculate automatically on changes; there’s no manual refresh key.

For a list of unique random numbers, say 10 numbers from 1 to 100 without repeats, do this:

  1. In column A, put =RAND() in A1:A10.
  2. In column B, put numbers 1 to 100 (or any range).
  3. Sort both columns by column A (Data > Sort).
  4. The first 10 values in column B are your random sample.

In Google Sheets, the functions are the same: =RAND() and =RANDBETWEEN(1,100). To get unique values, use =SORTN(A1:A100,10,,RANDARRAY(100),TRUE) — but note that RANDARRAY is available in both Excel 365 and Google Sheets.

Cryptographic Randomness: When It Matters

If you’re generating a password, a token, or a key, you need a generator that is unpredictable even to someone who knows the algorithm and the previous outputs. The gold standard is a cryptographically secure PRNG (CSPRNG) that draws entropy from hardware sources.

Practical examples:

  • Python: import secrets; secrets.randbelow(100) gives a secure random integer 0–99.
  • JavaScript: crypto.getRandomValues(new Uint32Array(1))[0] gives a 32-bit unsigned integer.
  • Command line (Linux/Mac): openssl rand -hex 16 gives 16 random bytes as hex.
  • Windows PowerShell: [System.Security.Cryptography.RandomNumberGenerator]::GetInt32(1,101) gives a secure integer 1–100.

Never use Excel’s RAND() or Google Sheets’ RAND() for passwords — they are not cryptographically secure. Use a password manager’s built-in generator instead.

Frequently Asked Questions

Can I generate a random number in Excel without it changing every time?

Yes. After generating the number, copy the cell and paste it as a value (right-click > Paste Special > Values). This replaces the formula with the static number. Alternatively, use a macro to generate a random number and store it as a value, but remember to save a copy of your workbook before running any macro.

Is a random number from Google truly random?

Google’s random number generator uses a pseudorandom algorithm seeded by your system’s entropy. It’s fine for casual use, but it’s not cryptographically secure. For true randomness, use a hardware-based service like random.org.

How do I generate a random number without repeats in a list?

Use a permutation. In Python, random.sample(range(1, 101), 10) gives 10 unique numbers from 1–100. In Excel, sort a list of numbers by a random column as described above. In Google Sheets, use =SORTN(A1:A100,10,,RANDARRAY(100),TRUE).

What’s the difference between RAND() and RANDBETWEEN()?

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. To get a decimal in a custom range, use =RAND()*(max-min)+min.

Can I generate a random number on a calculator?

Yes. Most scientific calculators have a RAND function that returns a decimal between 0 and 1. To get an integer, multiply by your range and round down. For example, on a TI-84, press MATH > PRB > rand, then multiply by 100 and use int(.

Is it safe to use a random number generator for a lottery?

For a personal lottery or a contest, a PRNG is fine. For a legally binding draw, you should use a certified random number service that provides an audit trail and uses true randomness. Check local regulations.

Alternatives and Final Thoughts

If you need randomness but don’t want to code, you have many options: physical dice, a deck of cards, or even a simple coin flip. For digital needs, the methods above cover almost everything. The key takeaway is to match the generator to the stakes. For a game, use RANDBETWEEN. For a password, use a password manager. For a scientific study, use a proper statistical package. And if you ever need to verify randomness, remember that no single number can prove randomness — you need a sequence and statistical tests.

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.