I am writing a program to create a matrix that will be filled with 1's and 0's.
var matrix = new int[3,3];
for (int i = 0; i < matrix.GetLength(0); i++)
{
for (int j = 0; j < matrix.GetLength(1); j++)
{
var random = new Random();
int rand = random.Next(0,2);
matrix[i, j] = rand;
}
}
for (int i = 0; i < matrix.GetLength(0); i++)
{
for (int j = 0; j < matrix.GetLength(1); j++)
{
Console.Write(matrix[i, j] + " ");
}
Console.WriteLine();
}
The program always returns a matrix filled with 1's. I want it to be random i-e that contains 1's and 0's. What can be the problem?