Binary Matrix Generator
Generate customizable binary matrices with patterns like random, symmetric, diagonal, Toeplitz, and identity. Export as PNG, SVG, or text.
About
A binary matrix is a matrix whose entries belong exclusively to the set {0, 1}. These structures appear in graph adjacency representations, digital image masks, combinatorial optimization, error-correcting codes, and finite automaton transition tables. Getting the density parameter d wrong in a Monte Carlo simulation or network adjacency test produces statistically invalid results. A truly random binary matrix of dimension m ร n with density d assigns each cell independently: aij = 1 with probability d, and 0 otherwise. This tool generates matrices up to 128 ร 128 using a seeded Linear Congruential Generator for full reproducibility.
Eight structural patterns are supported: pure random, symmetric (where aij = aji), identity, checkerboard, diagonal, Toeplitz (constant along diagonals), sparse, and block diagonal. The tool approximates ideal randomness via LCG. For cryptographic applications, use a CSPRNG instead. Results are exportable as PNG, SVG, or plain text for direct integration into papers, code, or presentations.
Formulas
Each cell aij of a random binary matrix is determined by comparing a pseudorandom number against the density threshold:
The pseudorandom function uses a Linear Congruential Generator (LCG):
where a = 1664525, c = 1013904223, m = 232 (Numerical Recipes constants). The normalized output r = Xn รท m falls in [0, 1).
For a symmetric matrix, only the upper triangle is generated randomly. The lower triangle mirrors it: aji = aij for all i < j. The expected number of 1s in a random matrix is E = m ร n ร d, where d โ [0, 1] is the density parameter.
Variable legend: m = row count, n = column count, d = density (probability of 1), X0 = seed value, aij = cell value at row i, column j.
Reference Data
| Pattern | Definition | Typical Use Case | Symmetry | Density Control | Deterministic |
|---|---|---|---|---|---|
| Random | aij = 1 if r < d | Monte Carlo simulation, fuzz testing | No | Yes | With seed |
| Identity | aij = 1 iff i = j | Linear algebra neutral element | Yes | No (fixed) | Yes |
| Symmetric | aij = aji | Undirected graph adjacency | Yes | Yes | With seed |
| Diagonal | aij = 0 if i โ j | Scaling operators, masks | Yes | Yes | With seed |
| Checkerboard | aij = (i + j) mod 2 | Texture generation, parity checks | Anti-symmetric | No (โ50%) | Yes |
| Toeplitz | Constant along each diagonal | Convolution, signal processing | No | Yes | With seed |
| Sparse | Density forced โค 15% | Large-scale graph storage, CSR input | No | Capped | With seed |
| Block Diagonal | Non-zero blocks along diagonal | Disconnected subgraph modeling | Partial | Yes | With seed |
| Upper Triangular | aij = 0 if i > j | DAG adjacency, Gaussian elimination | No | Yes | With seed |
| Lower Triangular | aij = 0 if i < j | Cholesky factor structure | No | Yes | With seed |
| Anti-diagonal | aij = 1 iff i + j = n โ 1 | Permutation matrices, reflections | Yes | No (fixed) | Yes |
| Hadamard-like | Rows are orthogonal binary vectors | Error-correcting codes (Walsh) | Yes | No (50%) | Yes |
| Circulant | Each row is a cyclic shift of the first | Cyclic codes, DFT structure | No | Yes | With seed |
Frequently Asked Questions
crypto.getRandomValues() or a CSPRNG. This tool is designed for simulation, education, and testing purposes.