HandyTools Hub

🎲 Random Number Generator

Generate random numbers with custom options.

🔒 100% client-side processing

Random numbers look simple until the source matters. This generator draws from the browser’s cryptographic random source, supports integers or two-decimal values, can enforce uniqueness, and lets you sort the results. It runs entirely on the page, which is why it works for offline use after loading and why the numbers never travel over the network.

How to Use

  1. Set the minimum and maximum values. The default 1 to 100 is a good starting range.
  2. Choose how many numbers you want, from 1 to 1000.
  3. Select integer or decimal type, and optionally tick unique and pick a sort order.
  4. Click Generate and copy the comma-separated results.

An example: min 1, max 100, count 6, unique on, ascending sort might return 3, 17, 42, 58, 76, 91. The exact numbers differ on every run.

Secure Randomness: crypto.getRandomValues vs Math.random

PropertyMath.random()crypto.getRandomValues()
Typepseudorandom, seeded internallycryptographically secure
Predictable from prior outputsyesno
Suitable for tokens, keys, drawsnoyes
Suitable for UI jitter, sample datayesyes, but overkill

This tool uses crypto.getRandomValues() and rejection sampling. Rejection sampling matters because the naive shortcut, taking a random byte and applying modulo, biases results toward low values whenever the range does not divide evenly into 256. Instead, out-of-range draws are discarded and repeated, so each allowed value is equally likely.

Options and Validation Rules

  • Minimum must be strictly less than maximum.
  • Count must be between 1 and 1000.
  • Unique mode applies to integers; the count cannot exceed the range size.
  • Decimal mode always uses two decimal places.
  • Sort offers none, ascending, or descending.

If unique generation cannot reach the requested count within a safety limit, it returns fewer values and reports that the result was truncated rather than looping forever. In normal use this only happens when the range is extremely tight.

Worked Examples

  • Five unique integers in [1, 5]: the result is always the digits 1 through 5 in some order, because the only possible unique set is the whole range.
  • Ten integers in [1, 10], ascending: a shuffled 1-10 sequence sorted back into order.
  • One decimal in [0, 1]: a value like 0.63, using both decimal digits.
  • Six-of-49 lottery style draw: min 1, max 49, count 6, unique on, then sort ascending for a readable ticket.

Notice that uniqueness and sorting change presentation, not the underlying draw. A sorted list is not less random; sorting only reorders values that were already selected.

What This Tool Does Not Do

Every value is drawn from a uniform distribution, so there is no weighting and no way to make some numbers more likely than others. It does not produce normal or Gaussian distributions, does not simulate dice with custom face probabilities, and does not keep a history between runs. It is also not a certified lottery or audit system: for regulated drawings you need a documented, independently verifiable process, not a browser page.

If you need random identifiers rather than numbers, use a dedicated token or UUID generator, which draws from the same secure source but formats the output for that purpose.

Sampling With and Without Replacement

Turning on unique changes the process from sampling with replacement to sampling without replacement. Without unique, each draw is independent and can repeat, so a list of ten numbers in [1, 10] might contain the same value three times. With unique, once a value is drawn it is removed from the pool, exactly like pulling lottery balls from a drum: a set of six unique numbers in [1, 49] can never repeat, and the order you see them in carries no extra information. Which you want depends on the question. A raffle, a survey sample, or a lottery draw needs unique; a simulation of independent dice rolls does not.

Practical Scenarios

  • Raffle draw: min 1, max number of entrants, count equal to the number of prizes, unique on.
  • Dice: min 1, max 6, count 5, integer, sort none for five independent rolls.
  • Test data: generate a batch of values to fill a spreadsheet column, then sort ascending for easier scanning.
  • Random assignment: min 1, max 2, integer, to split a list into two groups by treating 1 and 2 as labels.
  • Sampling by index: unique integers in [1, N] let you pick rows from a list; the indices are the sample.

The tool returns a plain comma-separated list, so pasting into a spreadsheet or a script usually needs no reformatting.

Security and Availability Notes

The cryptographic API is available in every current browser and requires a secure context, which means the page must be served over HTTPS or be running on localhost. If the browser exposes the API, this tool uses it directly and nothing about the numbers leaves your device. That combination makes it suitable for draws where fairness matters and for generating seeds, tokens, or test credentials, although a purpose-built UUID or password generator is the better choice once formatting requirements get specific.

Frequently Asked Questions

Does this tool use Math.random()?

No. It draws bytes from crypto.getRandomValues(), the browser's cryptographically secure generator, and uses rejection sampling so every value in the range has an equal chance. Math.random() is fine for animations and placeholder data, but it is predictable and should not be used for anything security-related.

Is the maximum value included in the range?

Yes. Integer mode draws from min to max inclusive. Min 1 and max 100 can return either 1 or 100, and the range size is max minus min plus 1.

Can I request more unique integers than the range contains?

No. The validator blocks it before generation, for example asking for 10 unique integers between 1 and 5. The largest possible unique set is the range size, so 1 to 5 allows at most five.

How many decimal places does decimal mode produce?

Two. Decimal values are generated uniformly across the range and then rounded to two places before being displayed, so the output looks like 37.42 rather than a long floating-point tail.

Why can't the minimum equal the maximum?

The tool requires min to be strictly less than max, because a single value is not a range. If you only need one number, set any real interval such as 1 to 2.

Can I set a seed to reproduce the same numbers?

No. Secure randomness has no seed and is not reproducible by design, so the same settings will produce a different list every time. If you need reproducible values, use a seeded generator in code instead.

Reviewed by the HandyTools Hub team · Last updated