Saturday, 8 June 2013

System.Random giving duplicates in runtime

System.Random giving duplicates in runtime

Normally, when I call this method of mine
    public static int Randomize(int min, int max)
    {
        Random r = new Random();
        return r.Next(min, max);
    }
I get a completely different number everytime.
But as soon as I start to use this method during runtime (60fps / 16 updates per ms), this method gives me almost only duplicates.
I can understand that Random could have not enough time to shuffle a random number, but how could I achieve a reliable random-method for ingame-runtime use?

No comments:

Post a Comment