I've written the following code for generating random float
and double
numbers.
public static class Statics
{
private static readonly Random random = new Random();
private static readonly object syncLock = new object();
public static double getRandomDouble(double min, double max)
{
lock (syncLock)
{
return random.NextDouble() * (max - min) + min;
}
}
public static float getRandomFloat(float min, float max)
{
lock (syncLock)
{
return (float)random.NextDouble() * (max - min) + min;
}
}
}
Is it OK that I'm using static
class
and methods for generating random numbers?
My program relies heavily on these methods so I want to make sure that the produced numbers are indeed random. These generators are being used by many objects but not simultaneously.