In this example, i’ll show you How to create a matrix of random integers in C#.

**C# Code:**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
static void Main(string[] args) { Random rnd = new Random(); const int MATRIX_ROWS = 5; const int MATRIX_COLUMNS = 5; double[,] matrix = new double[MATRIX_ROWS, MATRIX_COLUMNS]; for (int i = 0; i < MATRIX_ROWS; i++) { for (int j = 0; j < MATRIX_COLUMNS; j++) { matrix[i, j] = rnd.Next(1,100); } } for (int i = 0; i < MATRIX_ROWS; i++) { for (int j = 0; j < MATRIX_COLUMNS; j++) { Console.Write(matrix[i,j] + "\t"); } Console.WriteLine(); } Console.ReadKey(); } |

**Output:**