I have a list based of a custom class in C# and I am attempting to use a foreach loop to select each item in the index and using Random, randomly generate an INT for each item.
However, every item in the foreach loop changes to the same value. Is there away to change this?
this is my custom list:
List<patient> p = new List<patient>();
this is how i add items to the list:
p.Add(new patient(pname, pdob, ploc));
and this is the foreach loop in running inside a system.timers event.
foreach(patient ps in p)
{
ps.ploc = new Random().Next(80, 220);
}
an example output would be all items have a plocation(ploc) of 120 instead of each item having its own random.
Any solution would be greatly appreciated.