I am using a random number generator in my application. However, sometimes it hapeens to return exactly same value. My research shows that default Random constructor takes system time as seed. When same seed is used, same numbers are generated. So, if calling of my method is done in same system time (eg. with very little delay between calls) same numbers are generated.
So solution which looks good is to delay calls a little bit, so unique time is taken. My question is - what is atomic time unit in .NET seed generator - smallest number i can use for waiting so unique time is recognized and unique seed is generated?
Also, is right way to delay just make thread sleep?
for example
int smallestTimeUnit = 20; Thread.Sleep(smallestTimeUnit); Or is system time seed generation not reliable and should i implement my own way of Seed generation?
Thank you.
Randominstance that you use sequentially is far preferred (i.e. rather thannew Random()each time, you store an instance somewhere)