Ok. Here is what I know that won't work:
int Rand()
{
//will return the same number over and over again
return new Random().Next();
}
static Random rnd=new Random();
int Rand()
{
//if used like this from multiple threads, rnd will dissintegrate
//over time and always return 0
return rnd.Next();
}
This will work correctly, but if used by multiple threads, the CPU usage goes way up, which I don't want, and which I think is not necessary:
int Rand()
{
lock(rnd)
{
return rnd.Next();
}
}
So, is there a thread-safe Random class for c#, or a better way to use it?