mardi 14 mai 2019

Random Boolean always false or always true [duplicate]

This question already has an answer here:

I'm working on a cellular automaton in C#.NET WPF and want to randomly fill the grid.

public bool randBool()
{
    Random r = new Random();
    bool output = (r.Next(0, 2) == 1) ? true : false;
    return output;
}

private void fill()
{
    for(int i = 1; i <= 10; i++)
    {
        for(int j = 0; j <= 10; j++)
        {
            grid[i, j] = randBool();
        }
    }
}

However, the grid is always either entirely true or entirely false. Am I missing something really obvious here?




Aucun commentaire:

Enregistrer un commentaire