Search code examples
c#.netrandom

Better random function for C#


I'm generating many random numbers and I need a good function, since this doesn't help much:

public static class Randomizer
{
    static Random random = new Random((int)DateTime.Now.Ticks);

    public static int RandomInteger(int minimum, int maximum)
    {
        return random.Next(minimum, maximum + 1);
    }

    public static double RandomDouble()
    {
        return random.NextDouble();
    }
}

When I use this class, my numbers are very often the same. Do you have any simple idea how I can improve the randomness of the output of the randomizer?


Solution

  • See System.Security.Cryptography.RandomNumberGenerator