1001Ferramentas
๐ŸŽฒ Generators

Random Number Generator

Generate random numbers between a defined minimum and maximum. Option for unique numbers (no repetition) and configurable quantity.

How are random numbers generated?

Behind the numbers sits JavaScript's Math.random(), which returns uniformly distributed pseudo-random values. Tick the "no repetition" option and the Fisher-Yates shuffle takes over, making sure each number comes out just once.

Everything is computed inside your own browser.

Pseudo-random vs truly random: what the computer actually does

Computers cannot produce true randomness from arithmetic alone. What we call "random numbers" in software almost always comes from a pseudo-random number generator (PRNG) โ€” a deterministic algorithm that, given an initial seed, produces a long sequence of values that looks statistically random. JavaScript's Math.random() is a PRNG: in V8 it implements xorshift128+; older engines used Mersenne Twister. The output passes most uniformity tests but is fully reproducible if you know the seed and the algorithm.

A truly random number generator (TRNG), by contrast, harvests entropy from physical phenomena: thermal noise in a resistor, photon arrival times, radioactive decay, atmospheric noise (the source random.org famously uses), or the quantum behavior of vacuum fluctuations. The browser exposes a hybrid via crypto.getRandomValues() โ€” a cryptographically-secure PRNG (CSPRNG) reseeded from the operating system's entropy pool (/dev/urandom on Unix, CryptGenRandom on Windows). For lotteries, key generation, salts, tokens, and anything where predictability is a security flaw, always use the Web Crypto API.

Famous PRNG algorithms

  • Linear Congruential Generator (LCG) โ€” the classic x_{n+1} = (aยทx_n + c) mod m; fast but easily reverse-engineered.
  • Mersenne Twister (MT19937) โ€” period of 2^19937โˆ’1, the default in Python, R, and MATLAB for decades.
  • Xorshift / xoshiro / xoroshiro โ€” Marsaglia's family of bit-shifting generators; small state, excellent speed.
  • PCG (Permuted Congruential Generator) โ€” modern LCG variant with permutation output; good statistical quality at low cost.
  • ChaCha20 / Fortuna โ€” cryptographic generators used inside CSPRNGs.

Distributions: not all randomness is uniform

PRNGs natively output uniform values in [0,1). Real-world simulations often need other shapes: Gaussian (normal) via the Box-Muller transform, exponential via inverse CDF, Poisson for arrival counts, binomial for coin-flip sums. To get an integer in [min, max], the standard idiom is:

Math.floor(Math.random() * (max - min + 1)) + min

The modulo bias pitfall

A frequent mistake when using crypto.getRandomValues() is reducing a 32-bit integer with % n. If n does not divide 2^32 evenly, some outputs become slightly more likely than others โ€” invisible for n=6, catastrophic for cryptographic ranges. The fix is rejection sampling: discard samples that fall outside the largest multiple of n below 2^32 and draw again.

Standards and use cases

  • NIST SP 800-90A/B/C โ€” the U.S. specification for deterministic and entropy-based random generators.
  • Public draws โ€” require a CSPRNG plus auditable logs (or an externally-witnessed source like random.org's HMAC API).
  • Monte Carlo simulation โ€” Mersenne Twister or PCG are standard for Monte Carlo and statistical sampling.
  • Games โ€” Math.random() is fine for dice, loot, shuffling cards in casual play.
  • Cryptography โ€” never use Math.random() for keys, salts, IVs, or tokens; always CSPRNG.

FAQ

Is this generator fair for a public raffle? It uses Math.random(), which is statistically uniform but deterministic. For informal raffles it is fine; for prize draws with legal value, use a CSPRNG and keep an auditable record of seed, time, and result.

Are the results reproducible? Not from this tool โ€” every call uses fresh internal state. A seedable Mersenne Twister (via libraries like random-js) would let you replay the same sequence given a seed.

Can I avoid duplicates? Yes โ€” enable the "unique" option. Internally the generator either shuffles a range and slices N values, or rejects repeats with a Set. Note that uniqueness requires quantity โ‰ค (max โˆ’ min + 1).

What is "atmospheric noise"? random.org samples electromagnetic background noise picked up by tuned radios. Because it is driven by physical phenomena, the output is non-deterministic in a way no algorithm can match โ€” closer to a TRNG than a PRNG.

Related Tools

Generate random numbers your way

There are countless situations where you just want a number, or several, picked at random within a range, whether it's a quick draw or an experiment that needs an unbiased sample. The tool does this from the minimum, the maximum and the count you set in one go.

There's one option that changes a lot in practice: generating without repetition. In a draw with several winners, say, you don't want the same number showing up twice. Turn on unique values and every result in the list comes out different. In cases like simulating dice rolls or making test data, repetition is usually what you're after.

The draw uses the browser's own randomness source and runs locally. Nothing gets logged, so each set of numbers disappears the instant you close the page.