mardi 12 septembre 2017

Unique random number generation in c# [on hold]

The problem with the following technique is, it generates 0 (zero) most of the times.

How can I make it more random?

public class UniqueRandomNumber
{
    private Random random = new Random();
    private List<int> randomList = new List<int>();

    public int Next(int min, int max)
    {
        int newInt = 0;

        while(true)
        {
            newInt = random.Next(min, max);                

            if(!randomList.Contains(newInt))
            {
                randomList.Add(newInt);
                break;
            }
        }

        return newInt;
    }
}




Aucun commentaire:

Enregistrer un commentaire