Number Sorter
Sort a list of numbers ascending or descending.
Generate one or more random integers within any range you choose. Set the min and max, choose how many numbers to generate, and optionally enforce uniqueness or sort the output. Everything runs in your browser instantly.
Computers are deterministic machines, so software cannot produce randomness on its own. What it produces instead is pseudorandomness: a pseudorandom number generator (PRNG) takes a starting value called a seed and applies a fixed mathematical transformation over and over, emitting a sequence that passes statistical tests for randomness while being fully determined by that seed.
This has a practical consequence. Give the same PRNG the same seed twice and you get the identical sequence twice, which is enormously useful for reproducible simulations and test suites and completely disqualifying for anything an attacker might want to predict. Every PRNG also has a finite period, the length of the sequence before it starts repeating.
This is the single most important distinction on this page. Browsers expose two sources of randomness and they are not interchangeable.
| Math.random() | crypto.getRandomValues() | |
|---|---|---|
| Type | Fast general purpose PRNG | Cryptographically secure generator |
| Seeded from | An internal, implementation defined state | Operating system entropy pool |
| Predictable | Yes, output can be inferred from prior output | No, designed to resist prediction |
| Good for | Simulations, games, sampling, shuffling, animation | Tokens, passwords, session ids, keys, salts |
| Never use for | Anything security related | Nothing, though it is slower |
Math.random is statistically fine. Its numbers are uniformly distributed and perfectly adequate for a dice roll, a Monte Carlo simulation, or picking a random background image. The problem is that its internal state is small and its algorithm is public, so an observer who sees enough outputs can reconstruct the state and predict every future value. Password reset tokens, session identifiers, API keys, CSRF tokens, and cryptographic salts must therefore come from crypto.getRandomValues, which draws from entropy the operating system collects from genuinely unpredictable physical sources.
The obvious way to squeeze a random number into a range is to take it modulo the range size. The obvious way is subtly wrong whenever the range does not divide evenly into the generator output, because the leftover values at the top make some results more likely than others.
Imagine a generator producing 0 to 9 uniformly and you want a number from 0 to 2. Taking the value modulo 3 maps 0, 3, 6, and 9 onto 0; 1, 4, and 7 onto 1; and 2, 5, and 8 onto 2.
The fix is rejection sampling. Work out the largest multiple of your range that fits inside the generator output space, and simply discard any draw above it, then take the modulo. In the example above you would reject 9 and redraw, leaving 0 through 8, which divides evenly by 3 and gives each result exactly 33.3 percent. The cost is an occasional extra draw. The benefit is a genuinely uniform distribution, which matters a great deal when the numbers select a prize winner, an experiment bucket, or a character from a password alphabet.
A uniform distribution means every value in the range is equally likely on every draw. That is what you almost always want from a general purpose generator, and it is what makes averaging over many draws converge on the midpoint of the range.
Requesting unique numbers changes the model from sampling with replacement to sampling without replacement. Each value drawn is removed from the pool, so later draws come from a shrinking set. This is exactly what happens when you deal cards or draw lottery balls, and it is why you cannot generate more unique values than the range contains: asking for 20 unique numbers between 1 and 10 is impossible.
The standard algorithm for this is the Fisher-Yates shuffle. Walk the array from the end to the start, and at each position swap the current element with a randomly chosen element at or before it. It runs in linear time and produces every possible ordering with equal probability, which the naive approach of sorting by a random comparator does not.
Generating identifiers rather than plain numbers? Browse the full developer tools collection for UUID generation, hashing, and encoding utilities.
Random number generation has applications in games, simulations, statistical sampling, lottery draws, security token generation, and testing. Browser-based generators use pseudo-random algorithms seeded by system entropy, producing results that are statistically random and suitable for most non-cryptographic purposes. This tool gives you control over the range, count, uniqueness, and ordering of the generated numbers, making it useful for everything from picking a random winner to generating test data for your application.