How to fill two array with different values?

public static void Main(string[] args)
{
 int[,] arr1 = new int[5, 5];
 int[,] arr2 = new int[5, 5];

RandomFill(arr1);
RandomFill(arr2);
Print(arr1);
Print(arr2);
}

 public static void RandomFill(int[,] arr)
{
 System.Random Random = new System.Random();
//...
}

 public static void Print(int[,] arr)
{
 for (int i = 0; i < 5; ++i)
{
 for (int j = 0; j < 5; j++)
{
 System.Console.Write(arr[i, j] + " ");
}
System.Console.WriteLine();
}
System.Console.WriteLine();
}
 }
June 10th 19 at 16:37
2 answers
June 10th 19 at 16:39
Solution
private static Random Random = new System.Random();

public static void RandomFill(int[,] arr)
{
 for (int i = 0; i < 5; ++i)
{
 for (int j = 0; j < 5; j++)
{
 arr[i, j] = random.Next(2);
}
}
 }
June 10th 19 at 16:41
Solution
https://msdn.microsoft.com/en-us/library/system.ra...
Find on the page "Avoiding multiple instantiations" - there explanations.
that is in fact System.Random() need one , not several in a short period of time.

Find more questions by tags C#