Random Number Generator

A random number generator produces integers across a chosen range using a cryptographically secure source.

Set a minimum and maximum, choose how many values you need, and optionally require that no value repeats. Unique selection uses a sparse Fisher–Yates shuffle, so it completes in one pass with no retry loop even when the requested count approaches the size of the range.

Options

NameTypeDefaultDescription
countinteger10How many records to return, from 1 to 1000.
mininteger1Lowest value, inclusive.
maxinteger100Highest value, inclusive.
uniquebooleanfalseSet to true for values with no repeats.

Use cases

  • Sampling: Pick random rows or identifiers from a known range.
  • Load test inputs: Vary quantities, prices and identifiers in generated requests.
  • Draws and allocation: Select unique winners or shard assignments without repeats.

REST API

GET /api/v1/numbers

curl "https://ukaddressgenerator.org/api/v1/numbers?count=10"
{ "status": "success", "count": 5, "min": 1, "max": 100, "unique": true, "data": [42, 7, 91, 13, 68] }

Frequently asked questions

What happens if I ask for more unique values than the range contains?

The request is rejected with a clear message explaining how many distinct values the range holds, rather than looping forever.

Is the randomness suitable for security purposes?

It uses a cryptographically secure source, but for secrets use the password generator or a dedicated key generator.

Random numbers without the usual bugs

Uniform distribution, unique selection and range handling · 150 words

1. Uniformity

The common one-liner — a random float times the range — is adequate for display purposes but inherits any bias in the underlying source. This generator uses a cryptographically secure source with rejection sampling, so every value in the range is equally likely.

2. Unique selection without retry loops

Picking unique values by generating and rejecting duplicates degrades badly as the requested count approaches the size of the range: the last few picks can take thousands of attempts. A sparse Fisher–Yates shuffle solves it in a single pass, using memory proportional to the count rather than the range.

function uniqueRandom(count, min, max) {
  const range = max - min + 1;
  if (count > range) throw new Error('count exceeds range size');
  const swapped = new Map();
  const results = [];
  for (let i = 0; i < count; i += 1) {
    const j = i + secureIndex(range - i);
    const valueI = swapped.has(i) ? swapped.get(i) : min + i;
    const valueJ = swapped.has(j) ? swapped.get(j) : min + j;
    results.push(valueJ);
    swapped.set(j, valueI);
    swapped.set(i, valueJ);
  }
  return results;
}

3. Fail clearly

Asking for 100 unique values from a range of 10 is a programming error. The generator rejects it with a message naming the range size, rather than looping until the request times out.

More questions

Are these numbers suitable for cryptographic use?

They come from a secure source, but key material should be generated by a dedicated key generator in the environment where it will be used.

Related tools