Random Number Generator
Generate random integers and decimals between any two values with duplicate control, sorting, precision, bulk draws up to 1000, and a live distribution histogram.
Calculator
Range
Options
Random Draw Summary
Batch Diagnostics
Results
Distinct Values in Range
100
Inclusive count of possible outcomes
50.5000
(min + max) / 2 for a uniform draw
28.8661
Uniform-distribution spread
5
How many values each generation returns
5.0%
Draws divided by distinct values
—
Mean of the last generated batch
—
Observed span of the last batch
With replacement
Whether repeats are allowed
Browser PRNG draws mapped uniformly onto your inclusive range. Uniformity is statistical, not cryptographic — use a CSPRNG or hardware source for security-critical draws.
Visualizations
Draw Distribution (10 equal-width bins)
Range Coverage
Draws vs Distinct Values
Formula
A unit uniform draw rand in [0,1) is stretched over the closed range. Integers land on the whole-number lattice with probability 1/rangeSize each; decimals land on a 10^-p grid between min and max.
Alternative Form
Variables
| Symbol | Name | Unit | Description |
|---|---|---|---|
| rand | Unit uniform draw | [0,1) | Output of Math.random() |
| N | Range size | count | Distinct inclusive outcomes |
| min, max | Range limits | value | Inclusive endpoints, ordered first |
| p | Precision | places | Decimal places in decimal mode |
| E[X] | Expected mean | value | (min + max) / 2 |
| SD | Uniform std dev | value | (max − min) / √12 |
Explanation
Uniformity comes from giving every sub-interval of [0,1) equal width. Scaling and flooring preserves equal widths, so each integer inherits an equal slice of probability.
Derivation
Let U ~ Uniform[0,1). For integers with N outcomes, P(X = min+k) = P(k/N ≤ U < (k+1)/N) = 1/N. For decimals, the same U is scaled by (max−min), shifted by min, then rounded to p places.
Step-by-Step Calculation
Follow each step to understand how the result is calculated from your inputs.
Order the limits and measure the closed range.
Map a unit uniform draw onto the range.
Handle decimals on a fixed grid when requested.
Enforce the duplicate policy.
Apply the requested sort order after generation.
Check the batch against uniform expectations.
Worked Examples
See how the calculator works with different scenarios.
Scenario
Simulate one die roll with integers from 1 to 6.
Inputs
Calculation
rangeSize = 6 − 1 + 1 = 6 roll = 1 + floor(rand × 6) Example draw rand=0.52 → 1 + floor(3.12) = 4
Result
A single value 1–6, each with probability 1/6 ≈ 16.67%
Interpretation
Six equal slices of [0,1) map onto six faces. Repeating the draw converges to a flat histogram with mean 3.5.
Understanding Your Result
Your Result: Distinct Values in Range: 100
Typical range: Dice use 1-6, percentages 0-100, probabilities 0-1 decimals, lotteries match the ball pool such as 1-49. Coverage under 100% with duplicates off always succeeds; over 100% triggers the unique-shortfall warning.
What This Means
The headline numbers describe the sampling frame: how many distinct values exist, what their average should be, how many draws you take, and what share of the frame each batch covers.
Why It Matters
Naming the frame before drawing prevents the two classic errors — asking for more uniques than exist, and mistaking a browser PRNG for cryptographic randomness.
Professional Interpretation
For classroom demos and games the PRNG is ample. For regulated draws, cryptography, or gambling certification, replace it with a hardware or CSPRNG source such as random.org or NIST beacons.
Recommendations
- •Keep unique draws at or below the range size
- •Use decimals for continuous quantities, integers for counts
- •Leave sort off when draw order is the experiment
- •Batch large Monte Carlo runs in groups of 1000
- •Switch to crypto randomness for anything security-critical
- •Check the histogram: persistent tilt means a range bug
Educational Content
Introduction
This generator turns a unit uniform draw into fair outcomes in any interval you name. It supports whole numbers and fixed-precision decimals, unique-only sampling, sorting, and bulk batches with a live histogram.
Concept Explanation
Uniformity means equal probability per outcome. Stretching [0,1) over N outcomes gives each width 1/N; flooring assigns each slice to one integer. Decimals use the same stretch, then round to a 10^-p lattice.
Applications
Benefits
- •Any inclusive range, including negatives and BigInt-scale integers
- •Unique-only mode for sampling without replacement
- •Decimal precision from 1 to 10 places
- •Bulk draws to 1000 with sort control
- •Live histogram and coverage diagnostics
Limitations
- •PRNG output, not suitable for cryptography
- •Uniformity degrades past MAX_SAFE_INTEGER and on fine decimal grids
- •No seed control, so sequences are not replayable
- •At most 1000 draws per click
Best Practices
- •Size the range before choosing the count
- •Disable duplicates for lotteries, IDs, and brackets
- •Match precision to the measurement, not the maximum
- •Re-generate rather than hand-editing outliers
- •Document min, max, count, and duplicate policy with results
Common Misconceptions
Practical Tips
- •Use 1-6 integers for a die, 0-1 decimals at 4 places for probabilities
- •Turn duplicates off for lotteries, brackets, and unique IDs
- •Keep sort on None when dealing order matters
- •Cap batches at 1000 and loop for larger simulations
- •Check coverage before promising unique delivery
- •Use 2-4 decimal places unless science demands more
- •Never use browser draws for passwords or key material
Common Mistakes
Assumptions
This calculator makes the following assumptions to provide estimates:
Limitations
Be aware of these limitations when using this calculator:
Frequently Asked Questions
Answers to common questions about this calculator.
What is a random number?
How does this random number generator work?
Is Math.random() truly random?
What is the difference between true random and pseudo-random?
What are PRNGs?
What are TRNGs?
Can I use this generator for cryptography?
Can random numbers be predicted?
What is a seed?
What is entropy?
How do I generate unique numbers without duplicates?
Why do I get a "only N unique values" warning?
How do I generate random decimals?
How do I generate random integers?
What range can I use?
Can I generate negative random numbers?
Is there a limit on the number of results?
Does sorting affect randomness?
What precision should I pick for decimals?
What is a uniform distribution?
What is Monte Carlo simulation?
What is random sampling?
Can I use this for lottery numbers?
What is a CSPRNG?
How are RNGs tested for fairness?
What does the coverage percentage mean?
Why does a single-value range always return the same number?
How do I pick a random winner from a list?
Related Calculators
Explore more calculators related to this topic.
Related Guides
Deepen your understanding with these educational resources.
Glossary
Technical terms used in mortgage calculations explained in plain language.
- RNG
- A random number generator producing uniform draws over a range.
- PRNG
- Pseudo-random generator: fast deterministic algorithm mimicking randomness.
- TRNG / HRNG
- True (hardware) generator sampling physical entropy.
- CSPRNG
- Cryptographically secure PRNG resisting prediction attacks.
- Seed
- Initial PRNG state; identical seeds replay identical streams.
- Entropy
- Available unpredictability feeding secure generators.
- Sampling with replacement
- Draws where repeats are allowed; population is restored each pick.
- Sampling without replacement
- Draws where each value can appear at most once.
- Uniform distribution
- Every outcome has equal probability 1/N.
- Coverage
- Draws divided by distinct values, as a percentage.
Authoritative References
Trusted sources and standards referenced by this calculator.
Applicable Standards
Was This Calculator Helpful?
Page Information
2026-08-07
2.0.0
Free to use for educational and professional purposes.