Question: I need to create a random array of int with certain parameters. 

```
int[] test = new int[80];
Random random = new Random();

```

I need to assign 1's and 0's, randomly to the array. I know how to do that.

```
test[position] = Random.Next(0,2);//obviously with a for loop

```

But I need to have exactly 20 1's, but they need to be randomly positioned in the array. I don't know how to make sure that the 1's are randomly positioned, AND that there are exactly 20 1's. The rest of the positions in the array would be assigned 0.

Answer: 
I think you need to turn your thinking around.

Consider:

```
var cnt = 20;
while (cnt > 0) {
    var r = Random.Next(0, 80);
    if (test[r] != 1) {
        test[r] = 1;
        cnt--;
    }
}

```

Expanding explanation based on comments from CodeCaster. Rather than generate a random value to place in the array, this code generates and index to set. Since C# automatically initializes the test array to 0 these values are already set. So all you need is to add your 1 values. The code generates a random index, tests it to see if it isn't 1, if so it sets the array element and decrements a count (cnt). Once count reaches zero the loop terminates.

This won't properly function if you need more values than 0 and 1 that is true. Of course the questions explicitly stated that these were the needed values. 

"This causes horrible runtime performance". What!? Can you produce any prove of that? There is a chance that the index generated will collide with an existing entry. This chance increases as more 1's are added. Worst case is there is a 19/80 (~23%) chance of collision.
You can do

```
for (int i = 0; i < 20; i++)
{
    var rand = random.Next(0,80);
    if (test[rand] == 1)
    {
        i--;
        continue;
    }
    test[rand] = 1;
}

```

Remaining are automatically zero.