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

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

Random Matrix Generator Options

Matrix Type
Fill all matrix elements with random numbers.
Fill only diagonal elements with random numbers.
Fill space above the diagonal with random numbers.
Fill space below the diagonal with random numbers.
Generate the same numbers on both sides of the main diagonal.
Dimensions and Range
Output Format
Align all matrix elements in nice columns.

Random Matrix Generator Examples (click to try!)

Random 4x8 Matrix
This example generates a random rectangular matrix of 4×8 size. It fills all matrix with random integers from the range -9 to 9.
-6  2 5  9  0 0  9 1
 0  6 7 -5 -3 8 -6 2
 6  0 1 -6 -2 4  7 1
 2 -2 1  8 -1 6 -6 2
Regular Matrix
Number of rows.
Number of columns.
Starting value (inclusive).
Ending value (inclusive).
Random Integers
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Random Diagonal Matrix
This example generates a random diagonal matrix, that is, random numbers are placed only on the main diagonal. All other elements are zeros. It creates a matrix of size 6 by 6, with decimal fractions on the diagonal from the interval 0 to 9 (inclusive).
7.3   0   0   0   0   0
  0 2.4   0   0   0   0
  0   0 0.9   0   0   0
  0   0   0 7.8   0   0
  0   0   0   0 3.4   0
  0   0   0   0   0 2.1
Diagonal Matrix
Number of rows.
Number of columns.
Starting value (inclusive).
Ending value (inclusive).
Random Decimal Fractions
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
If you're generating fractions, what's their precision?
Random Upper Triangular Matrix
In this example, we fill an upper triangular (UT) matrix with dimensions 10 by 10 with random integers. As it's a UT matrix, all elements below the main diagonal are zeros. We set the range to [0, 10], and use a "Prettify Matrix" function to get a matrix with nice and even columns.
83 19 19 11 26  1  43 46  56 79
 0 60 47  6 81  9  20 44   5 48
 0  0 23 16 70 56  87  2  97 32
 0  0  0 46 22 16  39 27   1 23
 0  0  0  0 94 74  42 40  13 31
 0  0  0  0  0 25 100 46  72  0
 0  0  0  0  0  0  98  6  73 27
 0  0  0  0  0  0   0 64  90 60
 0  0  0  0  0  0   0  0 100 24
 0  0  0  0  0  0   0  0   0 37
Upper Triangular Matrix
Number of rows.
Number of columns.
Starting value (inclusive).
Ending value (inclusive).
Random Integers
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Random Lower Triangular Matrix
This example generates a random lower triangular (LT) matrix. A LT matrix has a property that all elements above the main diagonal are zero and only elements on the main diagonal and below it are filled. We set the matrix size to 4×4, choose fractions with the precision of three digits after the decimal point as matrix elements, and set the randomization range from 0 (start value) to 1 (end value).
0.213     0     0     0
0.266 0.595     0     0
0.017 0.175 0.102     0
0.033 0.418 0.298 0.764
Lower Triangular Matrix
Number of rows.
Number of columns.
Starting value (inclusive).
Ending value (inclusive).
Random Decimal Fractions
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
If you're generating fractions, what's their precision?
Random Symmetric Matrix
This example generates a random symmetric matrix. A symmetric matrix is always square (in our example, its size is 7×7) and has the same values on both sides of the main diagonal. For this example, we've chosen the random number range to be from 10 to 50.
19 40 41 48 16 38 17
40 28 33 31 15 47 22
41 33 22 25 22 38 48
48 31 25 16 32 10 41
16 15 22 32 24 27 14
38 47 38 10 27 30 30
17 22 48 41 14 30 46
Symmetric Matrix
Number of rows.
Number of columns.
Starting value (inclusive).
Ending value (inclusive).
Random Integers
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Random Binary Matrix
In this example, we generate a random rectangular (non-square) matrix with only two possible values – 0 and 1. We set matrix size to 40 columns and 20 rows and use the dot character to separate the matrix elements.
1.1.1.0.1.1.1.0.1.0.0.0.1.0.1.0.0.1.0.0.0.1.0.0.1.0.0.0.0.0.0.1.0.0.1.1.0.1.1.0
0.1.1.0.1.1.1.1.0.1.1.1.1.1.1.1.0.1.1.1.1.1.1.1.1.1.0.0.1.1.1.0.1.0.1.0.0.1.0.1
1.1.0.0.0.1.1.0.1.1.0.1.0.1.1.1.1.0.1.0.1.0.1.0.1.1.1.1.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0.0.0.0.0.0.1.1.0.1.0.0.1.1.1.0.1.0.1.0
1.1.1.0.1.0.1.0.1.0.1.1.0.1.0.0.0.0.1.1.0.1.0.0.1.0.1.0.0.1.1.1.1.1.0.1.1.0.1.1
0.1.0.1.1.1.0.1.0.1.1.1.1.0.0.1.1.0.1.1.1.0.0.0.0.0.1.0.1.0.1.0.1.0.0.0.0.0.0.0
1.1.1.1.1.0.0.1.1.1.0.1.0.0.0.0.0.1.0.0.0.1.1.1.1.0.1.1.1.0.1.1.1.1.1.0.1.0.1.0
1.0.1.1.0.1.0.1.1.1.1.0.0.1.0.0.1.0.1.1.1.0.0.1.1.1.0.1.0.1.0.1.1.0.1.1.1.1.1.0
Regular Matrix
Number of rows.
Number of columns.
Starting value (inclusive).
Ending value (inclusive).
Random Integers
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix

How Does This Random Matrix Generator Work?

This random matrix generator works entirely in your browser and is written in JavaScript. Internally, to represent the matrix, it creates a two-dimensional array of size m×n. The value m is the number of rows of the matrix (specified in options), and the value n is the number of columns (also specified in options). Then, depending on the selected type of matrix, this array is filled with random numbers using the Math.random() function. It fills the array with random values from the start (specified in options) to the end (specified in options). Finally, it converts array to a text matrix by applying the join() function twice, first time on column elements, and then on rows.

Created by Browserling

This random 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.