I often have to generate binary matrices so I created this simple online utility that does it for me. It lets you generate dense or sparse binary matrices of any size and shape. It works in the browser and is powered by alien technology from the future.

## Binary Matrix Generator Options

## Binary Matrix Generator Examples (click to try!)

0 1 1 1 0 1 0 1 0 1 0 0 0 1 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 0

𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟎 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏

[0][0][0][0][0][0][0][0][0][0] [0][0][0][0][0][0][0][0][0][0] [0][0][0][0][0][0][0][0][1][0] [0][0][0][0][0][0][0][0][0][0] [0][0][0][0][0][0][0][0][0][0] [0][0][0][0][0][0][0][0][0][0] [0][0][0][0][0][0][0][0][0][0] [0][0][0][0][0][0][0][0][0][0] [0][0][0][0][0][0][0][0][0][0] [0][0][0][0][0][0][0][0][0][0]

yes|yes|yes|yes|yes| no no|yes| no|yes|yes|yes yes| no|yes| no|yes|yes yes|yes|yes|yes| no| no no| no|yes| no|yes|yes

🟦🟦🟨🟨🟨🟨🟦🟨🟦 🟨🟨🟨🟨🟦🟨🟦🟨🟦 🟦🟦🟨🟦🟨🟦🟨🟨🟦 🟦🟦🟨🟦🟨🟨🟦🟦🟦 🟦🟦🟨🟦🟨🟦🟨🟦🟦 🟦🟨🟨🟦🟨🟦🟨🟦🟨 🟦🟦🟨🟦🟨🟦🟨🟨🟦 🟦🟦🟨🟦🟦🟦🟦🟦🟦 🟨🟦🟦🟦🟦🟦🟦🟦🟦

0 0 1 0 1 1 1 0 1 1 1 0 0 0 0

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

+ + + - + + - + - - - - - - - + - + + - + - - + - - - - + + + - - + - - + + - + - - - + + + + + + - + + - + + - - + + + + + - - + + - + + - - + + + + - + - - - + - - - - + - + + + - + + - - - - - - +

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0,0,0,0,0,1,1,1,0,1,0,1,1,0,1,1,1,0,0,1,1,0,0,1,1,1,1,0,1,0,0,1,1,1,0,1,0,0,0,1,0,1,1,1,0,0,1,0,1,0,1,0,0,1,0,0,1,0,0,1,1,1,0

## How Does This Binary Matrix Generator Work?

This binary matrix generator works entirely in your browser and is written in JavaScript. It generates a random boolean matrix of size `m×n`

(`m`

is the number of rows and `n`

is the number of columns) with 0 and 1 as its elements. If `m=n`

, then it's a square matrix. If `m>n`

, then it's a narrow and tall rectangular matrix. If `m<n`

, then it's a short and wide rectangular matrix. As JavaScript doesn't have matrices, it uses an array of arrays to represent a matrix. First, it creates an empty array `var matrix = []`

and then `push()`

es an empty array `[]`

into it `m`

times. When this two-dimensional array is created, it runs a double `for`

loop with counters `i = 0…m`

and `j = 0…n`

. The total number of iterations of this loop is the same as the number of elements of the binary matrix. Inside the loop, it fills the array position `matrix[i][j]`

with either a binary one or a binary zero. The matrix can be dense or sparse and you can control its density and sparsity via the `density`

option, which can range from 0 to 1. This value represents the probability of how often a binary one should be chosen for the `[i][j]`

-th element. For example, if the `density`

is 0.25, then the matrix will be filled with 1s about 25% of the time. If the `density`

is 0, then the matrix will be a completely sparse null matrix, filled with all 0s. If the `density`

is 1, then the matrix will be a completely dense unit matrix, filled with all 1s. In the loop, to generate 1s and 0s, the code creates a random number `prob`

between 0 and 1 using the `Math.random()`

function. If `prob <= density`

, then it sets the `matrix`

element `[i][j]`

to `1`

, else it sets it to `0`

. Instead of boolean values `1`

and `0`

, you can choose any other character or string. These values can be customized in the "one's symbol" and "zero's symbol" options. For example, you can set the one to be ① and zero to be ⓪. After the loop finishes, the array `matrix`

is converted to a string, by calling the function `join()`

two times. The first time it's called with `colSep`

column separator symbol and the second time it's called with the `rowSep`

row separator symbol.

### Created by Browserling

This binary matrix generator was created by me and my team at Browserling. Behind the scenes, it's actually powered by our web developer tools that are used by millions of people every month. Browserling itself is an online cross-browser testing service powered by alien technology. Check it out!

Secret message: If you love my tools, then I love you, too! Use coupon code TOOLLING to get a discount at my company.