C# Random method is initialized using the
clock. That's why it generates same value every time it calls. Here is the solution to generates different numbers:private static readonly Random random = new Random();
private static readonly object syncLock = new object();
public static int RandomNumber(int min, int max)
{
// synchronize
lock (syncLock)
{
return random.Next(min, max);
}
}
No comments:
Post a Comment