Best random function for C #

I generate a lot of random numbers, and I need a nice function, as 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 very often coincide. Do you have any simple idea on how I can improve randomizer performance?

Thank you Ivan

+3
source share
3 answers

Look at MiscUtil by John Skeet.

There is a static random class that works without problems.

By the way, do you need random or unique numbers?

0
source

, , , , , DateTime.Now.Ticks

. ,

-3
source

Source: https://habr.com/ru/post/1786936/


All Articles