Random Number Generator
Generate results with the Random Number Generator — set your parameters and get cryptographically-random output instantly.
Random Number Generator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser — no data is sent to any server.
Formula: floor(Math.random() × (max - min + 1)) + min
Worked example — e.g. 73
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer · Editorial policy
Random Number Generator Formula
floor(Math.random() × (max - min + 1)) + min
Math.random() returns a float in [0,1). Multiply by the range size and add the minimum to get a uniformly distributed integer in [min, max].
Random Number Generator — Worked Examples
Example 1: Single random number 1-100
Problem:Min: 1, Max: 100, Count: 1
Solution:floor(Math.random() × 100) + 1
Result:e.g. 73
Example 2: 5 lottery numbers 1-49
Problem:Min: 1, Max: 49, Count: 5
Solution:5 independent draws each uniformly distributed in [1,49]
Result:e.g. 7, 23, 31, 42, 48
Random Number Generator — Frequently Asked Questions
Is Math.random() truly random?
No. Math.random() is a pseudo-random number generator (PRNG) — it uses a deterministic algorithm seeded internally by the browser. The output appears random and passes statistical tests, but it is not cryptographically secure. For passwords, tokens, or security-sensitive values, use crypto.getRandomValues() instead. For games, simulations, and lotteries, Math.random() is perfectly adequate.
What is the difference between random and pseudo-random?
True random numbers derive from physical phenomena — radioactive decay, thermal noise, atmospheric static — and are fundamentally unpredictable. Pseudo-random numbers are produced by algorithms: given the same starting seed, the sequence repeats identically. Modern PRNGs like xorshift128+ (used in V8 for Math.random()) produce sequences that are statistically indistinguishable from true random for most practical purposes.
How to pick random lottery numbers?
Set Min to 1 and Max to the highest number in your lottery (e.g., 49 for most 6/49 lotteries), then set Count to how many numbers you need (e.g., 6). Each generated number is independently chosen from the full range. Note: since the lottery draw is also random, using a random generator gives you the same statistical odds as any other selection method.
What is a fair random number generator?
A fair RNG produces each number in the range with equal probability — a uniform distribution. This generator uses the formula: floor(Math.random() × (max - min + 1)) + min, which gives every integer in [min, max] an equal 1/(max-min+1) chance. Fairness can be verified by generating a large sample and confirming each value appears roughly equally often.
What are common uses for random number generators?
RNGs are used in games (dice rolls, card shuffles, procedural generation), statistical sampling (picking survey respondents, A/B test assignment), simulations (Monte Carlo methods, physics engines), lotteries and raffles, cryptographic key seeding, load balancing, and scientific research requiring randomized controlled trials.
Why do repeated numbers show up when I generate six values from 1 to 49?
Each value here is drawn independently, which statisticians call sampling with replacement: the previous draw does not remove that number from the pool. A physical lottery draws without replacement, so its six balls are always distinct. Drawing six independent values from 1 to 49 leaves them all distinct only about 73 percent of the time, so roughly one run in four contains at least one repeat. Generate a few extra values and discard duplicates if you need a distinct set.
How do you generate a set of distinct random numbers or shuffle a list?
Use the Fisher-Yates shuffle rather than repeated independent draws. Build the array of candidates, then walk from the last index down to the first, each time picking a random index between 0 and the current position inclusive and swapping the two entries. Every permutation becomes equally likely, and taking the first k entries of the shuffled array gives an unbiased sample without replacement. Sorting with a random comparator, such as sort(() => Math.random() - 0.5), is a common shortcut but does not give a uniform shuffle, because the comparator is inconsistent and the outcome depends on the sort algorithm.
Why does the formula add 1 to (max - min) before scaling?
Math.random returns a float in the half-open interval [0, 1), so it can equal 0 but never reaches 1. Multiplying by (max - min) alone would let the floor reach max only if the float hit exactly 1, which it cannot, so the top of the range would never appear. Using (max - min + 1) creates one bucket per integer, making the range inclusive at both ends and giving each value probability 1/(max - min + 1).
What does seeding mean, and can I reproduce the same sequence twice?
A seed is the starting internal state of a pseudo-random generator; the same seed replays the same sequence. Math.random deliberately exposes no seed, so its output cannot be reproduced from run to run. When a simulation, test fixture, or procedural level needs to be repeatable, implement a small seeded PRNG such as mulberry32 or xorshift and drive it from a fixed integer, keeping Math.random for cases where repeatability does not matter.
How can I check that the generated values really are uniformly distributed?
Generate a large batch over a small range, tally how often each value appears, and compare the tallies with the expected count of n divided by k, where k is the number of possible values. A chi-squared goodness-of-fit test formalises this by summing (observed minus expected) squared divided by expected across the k buckets and comparing against k minus 1 degrees of freedom. Keep the expected count per bucket at five or more for the test to behave well.
Random Number Generator — Background & Theory
History of the Random Number Generator
Related Calculators
🔐Password Generator
Generate secure random passwords
🎯Cluster Finder (K-Selection)
Determine optimal number of clusters using Elbow, Silhouette, and other methods
🧮P-Value from Z Calculator
Calculate pvalue from zcalculator with inputs, formulas, and instant results.
🧮Regression Coefficient Calculator
Calculate regression coefficient with inputs, formulas, and instant results.
🧮Relative Risk Calculator
Calculate relative risk with inputs, formulas, and instant results.