mardi 17 janvier 2017

C# Random.Next(min. max) return value less than min

Does anyone have any idea why does this piece of C# code return x = 0 and y = 0 (ocassionally) :

    public void NewPos() 
    {
        int x = 0;
        int y = 0;

        while (lstPosition.Where(z => z.Position.X == x && z.Position.Y == y).Count() != 0) {
            x = new Random().Next(4, 20) * 10;
            y = new Random().Next(4, 20) * 10;
        }

        NewPos.X = x;
        NewPos.Y = y; 

        Console.WriteLine(x + "  -  " + y );
    }




Aucun commentaire:

Enregistrer un commentaire