Random number 0's or 1's
c#, random
Solution
You can do it with `Random.Next(Int32, Int32)` method like;
int[] x = new int[10];
Random r = new Random();
while (x.Any(item => item == 1) == false)
{
for (int i = 0; i < x.Length; i++)
{
x[i] = r.Next(0, 2);
}
}
for (int i = 0; i < x.Length; i++)
{
Console.WriteLine(x[i]);
}
Example output;
0
0
0
1
1
1
0
1
1
0
Here a `DEMO`.
Remember, on `Random.Next(Int32, Int32)` method, lower bound is inclusive but upper bound is exclusive.
Problem
I am looking to generate 0's or 1's only for each array like: ``` int[] x = new int [10]; ``` I would like to generate 10 numbers either 0's or 1's and should not all 0's It's only like this: ``` Random binaryrand = new Random(2); ``` Thank you.