De Bruijn Sequence Generator
There are ten thousand four-digit codes, and typing each one separately takes forty thousand presses. There is a single sequence of ten thousand and three digits that contains all of them — every four-digit code appears in it exactly once, as a run of four consecutive presses. Nothing is repeated and nothing is missing. That is a de Bruijn sequence, and its length is not merely good but provably the shortest possible.
What this generator does
Builds the shortest cyclic sequence in which every possible run of the chosen length appears exactly once, and writes it out with the wrap-around spelled at the end so it can be used as a plain string.
How to use this tool
- Choose the set of symbols and how long each run should be.
- Build the sequence and read its length against the brute-force count.
- Copy it out — every run of that length appears somewhere inside.
- Note that the last few symbols repeat the first, which is how the wrap is written down.
Understanding the controls
- Symbols
- The set the sequence is built from: the ten digits for keypad codes, two symbols for binary, or letters where that reads more clearly.
- Run length
- How long each covered run is. The sequence's length is the number of symbols raised to this power, so it grows very quickly.
Common use cases
- Testing a keypad, lock or input field against every code
- Building a test input covering every state transition of a given depth
- Explaining why exhaustive testing need not mean repeating yourself
- Position encoding on a rotary sensor or marked strip
- A concrete example of a combinatorial construction
How this generator works
The construction goes through the shortest strings that cannot be written as a repeat of something smaller, concatenating those whose length divides the run length. That produces the minimum length exactly rather than approximately. Before display, every window is read off — wrapping past the end — and tallied, so a missing or repeated run would be reported rather than shipped.
Randomness and fairness
Nothing is random. The same settings always produce the same sequence, because there is a single shortest construction of this kind.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- The sequence grows as the symbol count raised to the run length, so long runs over many symbols are refused rather than shown.
- It covers runs of exactly the chosen length, not shorter or longer ones.
- For a real lock, codes are usually checked on entry rather than continuously, in which case this does not apply.
- One of many valid sequences exists for most settings; this construction gives a particular one.
Privacy and your data
The sequence is built in your browser. No settings or output are transmitted or stored.
Related generators
- Perfect Hash GeneratorFinds a hash that sends a fixed list of keys to distinct slots, with no collisions at all.
- Damm Check Digit GeneratorAdds a check digit that catches every single mistyped digit and every swap of two neighbours, and proves it by trying them all.
- UUID GeneratorAn RFC 4122 v4 UUID for development or testing use — cryptographically random, not sequential.
- Gray Code GeneratorBit sequences where consecutive entries differ in exactly one position, checked at every step including the wrap.