The type Random seeded by default in accordance with the current system time, which has finite detail.
When calling new Random().Next(1, 6) many times in a row, it creates many Random objects with the same initial value, which gives the same result. Calling Thread.Sleep(1) "solves" this problem by simply separating the constructs further from each other in time, increasing the likelihood of different seed values.
You need to save a specific Random object from one call to the following:
var randomNumbers = new Dictionary<int, int>(); var random = new Random();
Dan tao
source share