Random Groups Generator
Split a name list into N random balanced groups. Useful for class teams or events.
How to randomly split N people into K groups
Dividing a list of N people into K balanced groups at random is a classic problem and shows up in classrooms, hackathons, tournaments and Secret Santa draws. Two ingredients are needed: a fair shuffle of the list, and a deterministic rule to walk the shuffled list and assign each person to a group. The choice of shuffle is what determines whether the distribution is truly uniform.
Fisher-Yates: the right shuffle
The Fisher-Yates shuffle (originally published in 1938 and rewritten in modern form by Richard Durstenfeld in 1964) is the gold standard. In a single linear pass it produces each of the n! permutations with equal probability. The modern in-place version is:
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
It runs in O(n) time and O(1) extra memory. The naive alternative — arr.sort(() => Math.random() - 0.5) — is biased in several JavaScript engines (V8's TimSort, for example) and also slower at O(n log n). Never use it for anything that needs fairness.
Distributing the remainder when N is not divisible by K
If n = 10 and k = 3, three of the groups cannot all have the same size. The fair rule is round-robin: walk the shuffled list and drop person i into group i % k. Some groups end up with ⌈n/k⌉ = 4 and the rest with ⌊n/k⌋ = 3; the extras are distributed evenly across the first n mod k groups. This is what the generator above does.
Common use cases and constraints
- Classroom — split a 30-student class into pairs or trios for an exercise.
- Tournament brackets — seed a single-elimination bracket from a shuffled list.
- Pair programming / code review — random pairs that rotate every sprint.
- Hackathons — assign random colors, themes or table numbers.
- Secret Santa — same idea, plus a derangement check so that nobody draws their own name (regenerate or backtrack until satisfied).
Real-world variants often add constraints: do not put persons X and Y in the same group; balance by gender, seniority or skill; cap the size of each group. The simplest implementation is generate-and-test: shuffle, check constraints, reshuffle if violated. For dense constraints, switch to explicit backtracking or constraint propagation.
Round-robin vs random
Round-robin is deterministic — useful when fairness over multiple rounds matters (every player meets every other player exactly once). Random partition gives a single fresh draw and is preferable when the goal is to break habitual groupings. Many tournament formats start with a random seeding and then switch to round-robin or swiss-pairing rounds.
FAQ
Can the same person appear in two groups? No. The algorithm is a partition: each name from the input list is assigned to exactly one group.
What happens if N is smaller than K? Some of the K groups end up empty. The tool will create K groups regardless; the trailing ones simply have zero members.
Is the order inside each group also randomized? Yes — because the shuffle happens once over the entire list before partitioning, members within a group appear in random order too.
Is Math.random() good enough? For social/educational draws, yes. For anything with money, prizes or audit trails, use a cryptographically secure source (crypto.getRandomValues) and ideally a publicly verifiable seed.
Related Tools
TSID Generator (Time-Sorted ID)
Generate 64-bit time-sorted TSIDs ideal for distributed DB PKs, with timestamp decoder.
Random Number Generator
Generate random numbers between a defined minimum and maximum. Option for unique numbers (no repetition) and configurable quantity.
Random Emoji Generator
Generate a sequence of random emojis — pick theme (general, food, animals, sports) and quantity. For design, mockups and messages.
Time Blocking Schedule Generator
Set a start time, block length, break length and how many blocks to map out the whole day: 09:00 with 6 slots of 50 min and 10 min breaks between them.
Random Bytes Generator
Generate random bytes in hex, base64 or binary — using browser crypto.getRandomValues. For cryptographically secure keys, salts and tokens.
Fantasy Team Name Generator
Generate fictional sports team names in fantasy style: imaginary city + mythical animal. Useful for game projects, mockups and RPGs.