User Rating 0.0 โ˜…โ˜…โ˜…โ˜…โ˜…
Total Usage 0 times
Presets:

    
Is this tool helpful?

Your feedback helps us improve.

โ˜… โ˜… โ˜… โ˜… โ˜…

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.

binary matrix matrix generator 0 1 matrix random matrix identity matrix symmetric matrix toeplitz matrix

Formulas

Each cell aij of a random binary matrix is determined by comparing a pseudorandom number against the density threshold:

aij = {
1 if rand(i, j) < d0 otherwise

The pseudorandom function uses a Linear Congruential Generator (LCG):

Xn+1 = (a โ‹… Xn + c) mod m

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

PatternDefinitionTypical Use CaseSymmetryDensity ControlDeterministic
Randomaij = 1 if r < dMonte Carlo simulation, fuzz testingNoYesWith seed
Identityaij = 1 iff i = jLinear algebra neutral elementYesNo (fixed)Yes
Symmetricaij = ajiUndirected graph adjacencyYesYesWith seed
Diagonalaij = 0 if i โ‰  jScaling operators, masksYesYesWith seed
Checkerboardaij = (i + j) mod 2Texture generation, parity checksAnti-symmetricNo (โ‰ˆ50%)Yes
ToeplitzConstant along each diagonalConvolution, signal processingNoYesWith seed
SparseDensity forced โ‰ค 15%Large-scale graph storage, CSR inputNoCappedWith seed
Block DiagonalNon-zero blocks along diagonalDisconnected subgraph modelingPartialYesWith seed
Upper Triangularaij = 0 if i > jDAG adjacency, Gaussian eliminationNoYesWith seed
Lower Triangularaij = 0 if i < jCholesky factor structureNoYesWith seed
Anti-diagonalaij = 1 iff i + j = n โˆ’ 1Permutation matrices, reflectionsYesNo (fixed)Yes
Hadamard-likeRows are orthogonal binary vectorsError-correcting codes (Walsh)YesNo (50%)Yes
CirculantEach row is a cyclic shift of the firstCyclic codes, DFT structureNoYesWith seed

Frequently Asked Questions

The seed initializes the LCG's internal state X0. Identical seed, dimensions, density, and pattern will always produce the exact same matrix. This is critical for reproducible experiments. Changing the seed by even 1 produces a completely different output due to the multiplicative constant a = 1664525 amplifying small differences across iterations.
Sparse mode hard-caps density at 15% regardless of the slider position, ensuring matrices suitable for compressed sparse row (CSR) storage testing. Random mode with low density achieves similar visual results but doesn't enforce the cap. If you set density to 0.05 in Random mode, you get approximately the same output. Sparse mode is a convenience guard.
The identity matrix In is deterministic: aij = 1 iff i = j. Its density is always 1รทn. Applying an external density parameter would violate the definition. The same applies to Checkerboard and Anti-diagonal patterns.
No. The LCG used here (with constants from Numerical Recipes) is a fast PRNG but is not cryptographically secure. Its internal state can be predicted after observing a few outputs. For cryptographic binary matrices, use crypto.getRandomValues() or a CSPRNG. This tool is designed for simulation, education, and testing purposes.
A Toeplitz matrix satisfies aij = ai+1,j+1. The generator creates m + n โˆ’ 1 random binary values (one per diagonal) and maps each cell to its diagonal index j โˆ’ i. This structure appears naturally in discrete convolution and autocovariance matrices.
At 128 ร— 128 (16384 cells), the LCG generates all values in under 2ms on modern hardware. The canvas renderer draws each cell as a colored rectangle. Text output at this scale produces a 16384-character string. The tool remains responsive. Performance degrades only if you attempt to copy extremely large text outputs to clipboard, which browsers handle asynchronously.