Binary Sequence Generator
Generate random, weighted, LFSR, De Bruijn, and pattern-based binary sequences with entropy analysis, run-length stats, and export options.
About
Generating binary sequences that satisfy specific statistical properties is non-trivial. A naive Math.random call introduces bias from floating-point quantization, and simple concatenation ignores run-length constraints, autocorrelation, and entropy requirements. This tool implements seven distinct generation methods - from cryptographic-grade randomness via crypto.getRandomValues to deterministic LFSR polynomials and De Bruijn sequences - each producing verifiable output with Shannon entropy H computed per sequence. Incorrect bit distributions corrupt error-correction codes, invalidate Monte Carlo simulations, and break stream cipher test vectors.
Every generated sequence is accompanied by a statistical profile: bit frequency, longest run of 0s and 1s, Shannon entropy in bits, and a chi-squared uniformity score. The tool approximates ideal randomness assuming independent identically distributed bits; real-world channel noise and clock jitter are not modeled. Pro tip: for hardware testing (BERT), export balanced sequences with run-length constraints to avoid DC wander on AC-coupled links.
Formulas
Shannon entropy per bit for a binary sequence of length N with n1 ones:
where p = n1N is the proportion of 1-bits. Maximum entropy H = 1.0 bit occurs when p = 0.5.
The LFSR feedback function for an n-bit register with tap positions t1, t2, … is:
A maximal-length LFSR of degree n produces a period of 2n − 1 bits before repeating. The all-zero state is excluded.
Chi-squared uniformity test statistic:
where n0 and n1 are counts of 0-bits and 1-bits respectively, and N = n0 + n1. For a fair sequence, χ2 should fall below 3.841 at the 95% confidence level (1 degree of freedom).
Reference Data
| Method | Type | Period / Length | Use Case | Entropy (ideal) |
|---|---|---|---|---|
| Crypto Random | True PRNG (CSPRNG) | Unlimited | Cryptography, Monte Carlo | H ≈ 1.0 bit |
| Weighted Random | Biased PRNG | Unlimited | Channel simulation, Bayesian priors | H < 1.0 bit |
| LFSR (Fibonacci) | Deterministic | 2n − 1 | Spread-spectrum, PN codes, BIST | H ≈ 1.0 bit |
| De Bruijn B(2,n) | Combinatorial | 2n | Rotary encoders, exhaustive testing | H = 1.0 bit |
| Balanced | Constrained random | User-defined | Fairness testing, 8b/10b coding | H = 1.0 bit |
| Run-Length Limited | Constrained random | User-defined | Magnetic recording, DC-free codes | H ≤ 1.0 bit |
| Pattern Repeat | Deterministic | Pattern length | Clock signals, test fixtures | Depends on pattern |
| LFSR-3 (taps 3,2) | Deterministic | 7 | Simple PN code | H ≈ 0.985 |
| LFSR-4 (taps 4,3) | Deterministic | 15 | Scrambler seed | H ≈ 0.997 |
| LFSR-7 (taps 7,6) | Deterministic | 127 | ITU-T O.150 PRBS-7 | H ≈ 0.999 |
| LFSR-15 (taps 15,14) | Deterministic | 32767 | ITU-T O.150 PRBS-15 | H ≈ 1.0 |
| LFSR-23 (taps 23,18) | Deterministic | 8388607 | ITU-T O.150 PRBS-23 | H ≈ 1.0 |
| Gold Code | Composite LFSR | 2n − 1 | GPS C/A, CDMA | H ≈ 1.0 |
| Barker-13 | Fixed pattern | 13 | Radar, synchronization | H ≈ 0.961 |