Random Sample Generator

Draw a random sample of numbers from a population — with or without replacement, sorted for easy use.

How to use

  1. Enter the population size (N) — for example, 100 for a numbered list from 1 to 100.
  2. Enter the sample size (n) and choose whether numbers can repeat (with replacement).
  3. Click "Generate" to get a sorted list of random numbers. Use them for surveys, audits or classroom exercises.

About this tool

A random sample is a subset of a population chosen so that every member has an equal chance of being selected. This tool generates such a sample by number: you specify the population size and the sample size, and it picks n numbers at random from the range. Without replacement, each number appears at most once — this is the standard for surveys and audits. With replacement, numbers can repeat — useful for bootstrapping and simulation exercises.

The sampling without replacement uses the Fisher-Yates shuffle: it creates an array of all N numbers, shuffles it with a single pass of random swaps, and takes the first n elements. This guarantees a perfectly uniform distribution in O(N) time. The result is sorted for readability, since in most practical applications the order of selection does not matter — what matters is that every combination of n from N was equally likely.

The population can go up to one million, which is enough for any educational exercise or small-scale audit. The numbering starts at whatever value you choose (default 1), so you can match a numbered list of students, invoices or lab samples. Everything runs in your browser with Math.random(), which is not cryptographically secure — for a regulatory audit or a clinical trial randomisation, use a certified random number generator.

The formula

Fisher-Yates shuffle: for i from N-1 to 1, swap element i with element at random index [0, i]. Then take the first n elements. Probability of any single element being selected = n/N.

Frequently asked questions

Is the selection truly random?

It uses Math.random(), which is a pseudorandom generator. It is fine for education, surveys and non-critical sampling. For regulatory or cryptographic purposes, use a certified source of randomness.

Can I sample from a list of names instead of numbers?

This tool works with numbers. To sample names, number them and use the result to look them up — or use the name randomiser tool.

What is the difference between with and without replacement?

Without replacement, once a number is drawn it cannot appear again — each selection removes it from the pool. With replacement, every draw has the full pool available, so repeats are possible.

Why are the numbers sorted?

For readability. The order of selection is random, but once drawn, a sorted list is easier to work with — to look up records, for example. The randomness is in which numbers were chosen, not in their display order.

Does anything leave my browser?

No. The sample is generated in JavaScript on your device. Nothing is transmitted or stored.

Related tools

Long links? Shorten them for free

Vai.la turns any URL into a short link with click statistics, QR Code and your own biolink.

Vai.la is not responsible for how the tools are used or for decisions made based on their results.