Saw Tools

Random Number Generator

Allow duplicates
Sort ascending
CLICK GENERATE
ADVERTISEMENT

About this random number generator

This tool uses crypto.getRandomValues(), the cryptographically secure random source built into modern browsers. Unlike Math.random(), it's suitable for raffles, draws, security tokens and any case where predictability matters.

Common use cases

  • Raffles & giveaways: set a range, set "without duplicates" off, generate the winners.
  • Lottery picks: pick 6 from 1–49, sort ascending — done.
  • Random sampling: pick N items from a list of M.
  • Game/dice rolls: 1–6 for a die, 1–20 for a d20, etc.

Without duplicates

When duplicates are off, the count cannot exceed the range — picking 50 unique numbers between 1 and 10 is impossible. The tool will warn you if so.

Frequently asked questions

What is the difference between Math.random() and crypto.getRandomValues()?

Math.random() uses an internal PRNG (xorshift128+ in V8) whose 64-bit state can be reconstructed by observing a handful of outputs, allowing an attacker to predict all future values. crypto.getRandomValues() delegates to the OS CSPRNG (ChaCha20 or AES-CTR seeded by kernel hardware entropy), making prediction computationally infeasible. The rule is simple: Math.random() for games and animations, crypto.getRandomValues() for anything security-related.

Can I use this generator for an official draw or lottery?

For informal draws (picking a winner among colleagues, selecting a presentation order), yes — our generator uses crypto.getRandomValues(), guaranteeing an unbiased result. For draws with legal or monetary value, most jurisdictions require a certified auditable tool with full logging (seed, algorithm, timestamp) and an independent auditor or notary to attest the process. The tool can assist, but does not replace formal legal certification. Consult a certified auditing service for legally binding lotteries.

How do you generate a random number in a specific range without bias?

Applying rand() % n to a standard generator introduces a bias whenever the generator's range is not an exact multiple of n — smaller values appear slightly more often. The correct technique is rejection sampling: draw a number, accept it only if it falls in the unbiased zone, otherwise draw again. Our generator implements this via crypto.getRandomValues() with rejection, producing a perfectly uniform distribution regardless of the range you select.

Is it possible to test whether a stream of numbers is truly random?

Yes, through statistical test batteries: Diehard (Marsaglia), NIST SP 800-22 (the cryptographic reference), TestU01 BigCrush (the most rigorous). These tests check uniformity, absence of serial correlation, and binary distribution quality. Important caveat: passing these tests guarantees statistical quality, not cryptographic security. A generator can pass all tests and still be predictable if its internal state is small. Cryptographic security requires a CSPRNG, not just a good statistical distribution.

What is generator entropy and why does it matter at system startup?

Entropy measures the amount of unpredictability available in the system pool (in bits). At machine boot (or on a freshly cloned VM), this pool is sparsely filled: there have been no keyboard interrupts, no disk accesses, no network noise yet. If a cryptographic key is generated too early, the seed may be weak and therefore guessable. Linux 5.6+ blocks getrandom() until enough initial entropy has accumulated. In cloud production environments, tools like VirtIO-RNG or entropy daemons (haveged, jitterentropy) feed the pool at startup to prevent this problem.