GenerateRandomSearch

Group Constraint Solver

Random group generators are fine until two people cannot be in the same group, or two must be. Then it stops being a shuffle and becomes a constraint problem: joining people is straightforward, keeping them apart is graph colouring, and the two together can be impossible in ways that are not obvious from the rules. This solves it, and when there is genuinely no arrangement it names the rule that broke it instead of silently ignoring one.

What this generator does

Merges everyone joined by a must-be-together rule into a single block, then searches for a way to place the blocks into groups without exceeding a group's size or putting a must-be-apart pair together. Where no such placement exists it reports why.

How to use this tool

  1. List everyone, one per line.
  2. Choose how many groups you want.
  3. List the pairs who must be together, and the pairs who must be apart.
  4. Read the groups, or the reason no arrangement exists.

Understanding the controls

People
One per line. Names have to be unique, since the rules refer to them by name.
How many groups
Group sizes come out as even as the rules allow, and no group holds more than the list divided by this, rounded up.
Must be together
One pair per line, written as “Ada and Ben” or “Ada, Ben”. These chain: joining three overlapping pairs moves all four people as a single block.
Must be apart
One pair per line, in the same form. If they cannot all be honoured the tool says so rather than quietly dropping one.

Common use cases

  • Grouping a class where certain children must be separated
  • Splitting a team so that job-shares stay together
  • Making project groups with a rule about who works with whom
  • Finding out early that a set of rules cannot all be met
  • Understanding why one more group would fix an impossible split

How this generator works

Must-be-together rules are handled first, by union-find: each rule joins two people, and chains of rules merge into blocks that must move as one. That immediately exposes two kinds of impossibility — a pair that must be apart but has been joined into one block, and a block larger than a group can hold — and both are reported by name. What remains is a colouring problem, solved by placing blocks largest-first with backtracking, skipping arrangements that only differ by which empty group was used. Before display every person is confirmed to appear exactly once, every group is checked against the size limit, and every rule of both kinds is re-tested against the finished groups.

Randomness and fairness

Nothing here is random. The same list and the same rules always give the same groups — this solves rather than shuffles, and the random group generator is the one for an unconstrained draw.

For how randomness is produced across the whole site, see how Generate Random works.

Limitations and good to know

  • Groups come out as even as the rules allow, but a large must-be-together block can force uneven sizes and there is no way round that.
  • Keeping people apart is graph colouring, which is genuinely hard. With many overlapping rules the search is capped, and it says so rather than running indefinitely.
  • Where several arrangements satisfy every rule, one of them is returned. It is a valid answer rather than the only one.
  • A rule mentioning somebody not on the list is rejected rather than ignored, since a silently dropped rule is the failure mode worth avoiding here.

Privacy and your data

Names and rules stay in your browser. Nothing is uploaded, stored, or included in analytics — only that a split was produced.