Possible Duplicate:
Random number generator not working the way I had planned (C#)
I have LinkedList of LinkedList, and when I try to dispaly after filling, the raws are the same, but the most curious is that in debug mode it dispalays different rows. BTW I have VS11 beta.
private LinkedList<LinkedList<int>> grid = new LinkedList<LinkedList<int>>();
public void CreateMatrix(int rows, int coloumns, int maxSize)
{
for(int i = 0; i < rows;i++)
{
grid.AddFirst(generateList(coloumns, maxSize));
}
}
private LinkedList<int> generateList(int size, int maxSize)
{
var ranodGenerator = new Random();
var list = new LinkedList<int>();
for (int j = 0; j < size; j++)
{
list.AddFirst(ranodGenerator.Next(maxSize));
}
return list;
}
public void DisplayMatrix()
{
foreach (var list in grid)
{
foreach (var i in list)
{
Console.Write(i+ " ");
}
Console.WriteLine();
}
}
So after
MatrixManager matrixManager = new MatrixManager();
matrixManager.CreateMatrix(4,4,200);
matrixManager.DisplayMatrix();
it will display 4 identical rows
134 3 45 26
134 3 45 26
134 3 45 26
134 3 45 26
but should display different