Thousands of tools! Check out Online Tools – I have now added thousands of tools.

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

Rows and Columns
Density and Elements
Output Format
Align all matrix elements in nice columns.

Binary Matrix Generator Examples (click to try!)

Square Binary Matrix
In this example, we create an 8 by 8 logical matrix. The matrix is half-dense/half-sparse as we have set the density parameter to 0.5, which means that the probability for 1s and 0s is the same and equal to 50%.
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
Number of rows.
Number of columns.
The probability of generating a binary-one value.
Binary-one symbol.
Binary-zero symbol.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Dense Boolean Matrix
This example generates a dense 8×10 matrix, using the mathematical bold font for binary values. The binary-ones use the "𝟏" symbol and binary-zeros use the "𝟎" symbol. As the density option is set to 0.99, then in 99% of the cases the matrix elements are set 𝟏s and only in 1% of the cases, they are set to 𝟎s.
𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏
𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏
𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏
𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏
𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏
𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟎 𝟏 𝟏
𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏
𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏 𝟏
Number of rows.
Number of columns.
The probability of generating a binary-one value.
Binary-one symbol.
Binary-zero symbol.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Sparse Boolean Matrix
In this example, we set the density coefficient to 0.01 and generate a boolean matrix with 100 elements. As 0.01×100 is 1, then the output matrix is expected to be super sparse and have only one 1 and ninety-nine 0s. We have also customized the values that are used for true and false and they are set to "[1]" for true and "[0]" for false.
[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]
Number of rows.
Number of columns.
The probability of generating a binary-one value.
Binary-one symbol.
Binary-zero symbol.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
"Yes"/"No" Matrix
In this example, we set the logic domain to {"yes", "no"}. That means that instead of a 1, the program generates "yes" and instead of a 0, it generates "no". Since the density is set to 0.7, the probability of generating "yes" is 70% and the probability of generating "no" is 30% (100% - 70%). The output format is also customized and the matrix elements are separated with pipe symbols.
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
Number of rows.
Number of columns.
The probability of generating a binary-one value.
Binary-one symbol.
Binary-zero symbol.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Colorful Matrix
In this example, we generate a 9×9 logical matrix that uses colors for truthy and falsy values. It uses blue and yellow squares for binary values 1 and 0. The probability of generating a blue square is 60% and the probability of a yellow square is 40%.
🟦🟦🟨🟨🟨🟨🟦🟨🟦
🟨🟨🟨🟨🟦🟨🟦🟨🟦
🟦🟦🟨🟦🟨🟦🟨🟨🟦
🟦🟦🟨🟦🟨🟨🟦🟦🟦
🟦🟦🟨🟦🟨🟦🟨🟦🟦
🟦🟨🟨🟦🟨🟦🟨🟦🟨
🟦🟦🟨🟦🟨🟦🟨🟨🟦
🟦🟦🟨🟦🟦🟦🟦🟦🟦
🟨🟦🟦🟦🟦🟦🟦🟦🟦
Number of rows.
Number of columns.
The probability of generating a binary-one value.
Binary-one symbol.
Binary-zero symbol.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Binary Vector
This example creates a one-dimensional binary matrix with a length of 15 elements. This matrix is equivalent to a 15-dimensional binary row vector. This vector is neither dense nor sparse as the probability for picking a 1 or a 0 is the same 50%.
0 0 1 0 1 1 1 0 1 1 1 0 0 0 0
Number of rows.
Number of columns.
The probability of generating a binary-one value.
Binary-one symbol.
Binary-zero symbol.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Just Ones
In this example, we're having fun and we have erased the element for zeros. As a result, the output matrix has only ones and zeros are empty.
        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
Number of rows.
Number of columns.
The probability of generating a binary-one value.
Binary-one symbol.
Binary-zero symbol.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Just Zeros
This example is the inverse of the previous example. Here, we have erased ones and only left zeros in the output.
    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  
Number of rows.
Number of columns.
The probability of generating a binary-one value.
Binary-one symbol.
Binary-zero symbol.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Pluses and Minuses
We're continuing to have fun and in this example, we have customized both the binary one and the binary zero symbols. We are using a plus for a one and a minus for a zero.
+ + + - + + - + - -
- - - - - + - + + -
+ - - + - - - - + +
+ - - + - - + + - +
- - - + + + + + + -
+ + - + + - - + + +
+ + - - + + - + + -
- + + + + - + - - -
+ - - - - + - + + +
- + + - - - - - - +
Number of rows.
Number of columns.
The probability of generating a binary-one value.
Binary-one symbol.
Binary-zero symbol.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Matrix of Ones
In this example, we have set the density parameter to 1, which means that 100% of the time a one will be used for the matrix element. As a result, all matrix elements are 1s and the resulting binary matrix is a 5-by-5 all-ones matrix.
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
Number of rows.
Number of columns.
The probability of generating a binary-one value.
Binary-one symbol.
Binary-zero symbol.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Zero Matrix
This example is the inverse of the previous example. Here, we have set the density option to 0, which means that 0% of the time a one will be used as a matrix element. As all elements in the output matrix are 0, we have generated a null matrix.
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
Number of rows.
Number of columns.
The probability of generating a binary-one value.
Binary-one symbol.
Binary-zero symbol.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
CSV Binary Values
In this example, we have set the matrix element separator and the matrix row separator to a comma. This transforms the binary matrix into a long comma-separated string with zeros and ones. As the matrix dimension is 7×9, the output string has 63 comma-separated boolean values.
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
Number of rows.
Number of columns.
The probability of generating a binary-one value.
Binary-one symbol.
Binary-zero symbol.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix

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.