# Random Number Generator

URL: https://hifreetools.com/random/random-number-generator

> Generate random numbers within a range you set. Choose how many to draw, whether to allow duplicates, and whether to sort the results.

## Quick answer

A random number generator produces numbers within a range you choose. Set a minimum and maximum, pick how many you want, and decide whether repeats are allowed. This tool draws uniform, unbiased numbers using your browser’s secure random generator.

## Formula

- size = max − min + 1; each number = min + uniform index in 0…size−1 (crypto.getRandomValues, rejection sampling)
- no duplicates: partial Fisher–Yates shuffle (selection without replacement)

Numbers are drawn uniformly from your inclusive min–max range using the browser’s Web Crypto API with rejection sampling, which avoids the slight bias a plain modulo would introduce. With duplicates turned off, drawn numbers are removed from the pool so each result is unique (a random selection without replacement).

## Inputs

- Minimum (-1000000000 to 1000000000); default 1
- Maximum (-1000000000 to 1000000000); default 100
- How many (1 to 10000); default 1
- No duplicates; default false
- Sort results; default false

## Worked examples (computed by the page's own function)

- Minimum = 1, Maximum = 100, How many = 1 → Your numbers = 7, Possible values = 100  (100 possible values (1 … 100), each equally likely)
- Minimum = 1, Maximum = 49, How many = 6, No duplicates = true → Your numbers = 32, 35, 28, 29, 49, 13, Possible values = 49  (49 possible values (1 … 49), each equally likely)
- Minimum = -50, Maximum = 50, How many = 3 → Your numbers = 0, 2, -50, Possible values = 101  (101 possible values (-50 … 50), each equally likely)

## Verification

Checked against 16 reference cases (expected values computed independently). Reviewed 2026-10-27. Latest change 2026-10-28: Moved to the schema generator renderer with a sourced ledger; same range, count, no-duplicates and sort options. Bounds are now whole numbers within ±1,000,000,000.

## FAQ

**How do I generate a random number in a range?**
Enter a minimum and maximum, set how many numbers you want, and generate. Results are drawn uniformly from the inclusive range you chose.

**Can I avoid duplicate numbers?**
Yes. Turn off duplicates to draw unique numbers without replacement — useful for raffles or lottery-style picks.

**Are the numbers truly random?**
They use the Web Crypto API, a cryptographically secure source, with rejection sampling to keep every value equally likely.

**Is the range inclusive?**
Yes. Both the minimum and the maximum can be produced.

**Does it improve my odds in a lottery?**
No. Random numbers can’t predict or improve lottery outcomes. This tool is for everyday fair selection, not gambling.

**What's rejection sampling and why do you use it?**
Rejection sampling ensures every number in your range is equally likely. A naive modulo approach slightly favors lower numbers; rejection sampling avoids that bias by discarding values outside an aligned multiple of your range.

**Can I generate negative numbers?**
Yes—set the minimum to any negative number (e.g., –50) and the maximum to any positive number (e.g., 50). The range works exactly the same.


## Sources

- [Wikipedia — Discrete uniform distribution](https://en.wikipedia.org/wiki/Discrete_uniform_distribution)
- [Wikipedia — Fisher–Yates shuffle](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle)
- [Wikipedia — Rejection sampling](https://en.wikipedia.org/wiki/Rejection_sampling)
- [MDN — Crypto.getRandomValues()](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues)

Runs in the browser; nothing is uploaded. Cite as: HIFreeTools, "Random Number Generator", https://hifreetools.com/random/random-number-generator
