Stax
Tools

Random Number Generator

Generate secure random numbers in any range.

Click Generate to produce random numbers using crypto.getRandomValues()

Uses for random numbers

  • Lottery / raffle — fair random draws for giveaways
  • Dice simulation — tabletop games, probability experiments
  • Random sampling — picking random items from a list for testing
  • Password seeds — generating random PIN codes or OTPs
  • Education — statistics exercises, probability demonstrations
  • Games — random card shuffles, team assignments

Math.random() vs crypto.getRandomValues()

Math.random()uses a deterministic pseudorandom algorithm seeded at startup. For most games and simulations it's fine. But crypto.getRandomValues()draws from the OS entropy pool — the same source used for cryptographic key generation. This tool always uses the secure version.

Common use cases with real scenarios

Teachers running classroom raffles set min=1, max=30, count=1 to pick a random student from a class roster without bias. Developers writing unit tests generate a batch of 100 unique random IDs in range 10000–99999 to seed test databases. Tabletop RPG players simulate an 8-sided dice roll by setting min=1, max=8. Statistics students demonstrating the law of large numbers generate 1,000 numbers between 1 and 10 and verify each digit appears roughly 100 times. Security teams generate random PIN codes for one-time access credentials using the secure CSPRNG mode so the values cannot be predicted even if the seed time is known.

How cryptographic randomness works in the browser

crypto.getRandomValues()is part of the Web Cryptography API available in all modern browsers since 2014. It fills a typed array (Uint32Array in this tool) with bytes sourced from the operating system's entropy pool — hardware events, interrupt timing, and other unpredictable system sources. UnlikeMath.random(), the output cannot be predicted by knowing the time or state of the browser. This makes it suitable for PIN generation, one-time codes, and any randomness that must be resistant to guessing attacks.

Fisher-Yates shuffle and the no-duplicates mode

When no-duplicates is enabled, the tool builds the full integer range, shuffles it using the Fisher-Yates algorithm (each element swapped with a cryptographically random index), then takes the first N elements. This guarantees uniform distribution — every permutation is equally likely. The naive approach of "keep generating until we get something new" has poor performance as the list fills up and birthday-paradox collisions become frequent; Fisher-Yates runs in exactly O(N) time regardless of density.

Frequently asked questions

Is this truly random?
This generator uses crypto.getRandomValues() — the browser's cryptographically secure pseudorandom number generator (CSPRNG). It is significantly more random than Math.random() and suitable for security-sensitive applications.
What does 'no duplicates' do?
When enabled, each number in the output appears only once — like drawing numbers from a hat without replacement. This uses a Fisher-Yates shuffle on the full range. Note: you cannot generate more unique numbers than there are integers in the range.
What is the maximum number of values I can generate?
You can generate up to 1,000 random numbers at once. For most use cases (lottery picks, random sampling, dice simulation) this is more than sufficient.
How do I simulate a dice roll?
Set Min to 1 and Max to 6 for a standard die. For multiple dice, increase the count. For a D20 (used in tabletop games), set Min to 1 and Max to 20.
Can I use this for a lottery or raffle?
Yes. Set Min to 1 and Max to your lottery range (e.g., 49 for UK Lotto), enable No Duplicates, and set count to the number of balls drawn (e.g., 6). This gives a fair random draw.

Related tools