User Rating 0.0
Total Usage 0 times
1 – 10,000
1 – 100
Presets:
Is this tool helpful?

Your feedback helps us improve.

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.

binary sequence random binary LFSR bit generator binary string De Bruijn entropy pseudo-random binary pattern

Formulas

Shannon entropy per bit for a binary sequence of length N with n1 ones:

H = p log2 p (1 p) log2 (1 p)

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:

bnew = bt1 &xor; bt2 &xor;

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:

χ2 = (n0 n1)2N

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

MethodTypePeriod / LengthUse CaseEntropy (ideal)
Crypto RandomTrue PRNG (CSPRNG)UnlimitedCryptography, Monte CarloH 1.0 bit
Weighted RandomBiased PRNGUnlimitedChannel simulation, Bayesian priorsH < 1.0 bit
LFSR (Fibonacci)Deterministic2n 1Spread-spectrum, PN codes, BISTH 1.0 bit
De Bruijn B(2,n)Combinatorial2nRotary encoders, exhaustive testingH = 1.0 bit
BalancedConstrained randomUser-definedFairness testing, 8b/10b codingH = 1.0 bit
Run-Length LimitedConstrained randomUser-definedMagnetic recording, DC-free codesH 1.0 bit
Pattern RepeatDeterministicPattern lengthClock signals, test fixturesDepends on pattern
LFSR-3 (taps 3,2)Deterministic7Simple PN codeH 0.985
LFSR-4 (taps 4,3)Deterministic15Scrambler seedH 0.997
LFSR-7 (taps 7,6)Deterministic127ITU-T O.150 PRBS-7H 0.999
LFSR-15 (taps 15,14)Deterministic32767ITU-T O.150 PRBS-15H 1.0
LFSR-23 (taps 23,18)Deterministic8388607ITU-T O.150 PRBS-23H 1.0
Gold CodeComposite LFSR2n 1GPS C/A, CDMAH 1.0
Barker-13Fixed pattern13Radar, synchronizationH 0.961

Frequently Asked Questions

Crypto-random uses the browser's crypto.getRandomValues, which draws from the OS entropy pool (hardware interrupts, thermal noise). It is non-deterministic and suitable for key generation. An LFSR is a deterministic shift register - given the same seed and taps, it always produces the identical sequence. LFSR output has excellent autocorrelation properties (single peak) but is cryptographically weak because the internal state can be reconstructed from 2n consecutive output bits via the Berlekamp - Massey algorithm.
Setting the probability of a 1-bit to p yields Shannon entropy H = p log2 p (1 p) log2(1 p). At p = 0.5, entropy is maximal at 1.0 bit. At p = 0.1, entropy drops to approximately 0.469 bit. This matters for channel capacity calculations: a binary symmetric channel with crossover probability p cannot exceed capacity 1 H(p).
A De Bruijn sequence B(2, n) is a cyclic binary string of length 2n in which every possible binary substring of length n appears exactly once. It is used in absolute rotary encoders (a single track encodes all 2n angular positions), in card tricks requiring a binary sequence with unique windows, and for exhaustive test-pattern generation where every n-bit combination must be exercised.
The chi-squared test at 95% confidence expects roughly 5% of truly random sequences to exceed the critical value 3.841. This is by design - a statistical test has a false-positive rate equal to its significance level. Short sequences (below 100 bits) are especially prone to this because random fluctuations in bit counts are proportionally larger. Do not conclude the generator is broken from a single failure; run multiple sequences and check the overall pass rate.
Limiting maximum run length to k bits removes low-frequency content from the power spectral density. In magnetic and optical recording (e.g., CD uses EFMPlus with max run 11), this ensures the signal has sufficient transitions for clock recovery. The trade-off is reduced entropy: a run-length-limited sequence carries fewer than 1.0 bit of information per symbol because not all binary strings are valid codewords.
A single LFSR is cryptographically insecure. An attacker observing 2n consecutive bits from a degree-n LFSR can reconstruct the feedback polynomial and predict all future output using the Berlekamp - Massey algorithm in O(n2) operations. Stream ciphers like A5/1 (GSM) combine multiple LFSRs with irregular clocking, and modern designs (Trivium, Grain) add nonlinear feedback functions. For any security-sensitive application, use the crypto-random method.