I'm having some trouble with a weird code structure and I can't seem to find an answer to the problem after 2 hours of try and error.

I have 2 variables and an array structure with some sub arrays (this is important for later on) the system is to big to post the full code so here is the problem part:

```
$counter= 10;
$times = 20;
//Random 1 / 0

while($times > 0){
    $number = rand(0,1);
    if($number == 1) {
        $counter++;
    } else {
        $counter--;
    }
$times--;
}

```

So this is straightforward, problem however is that the $total which is 10 at the start has to end on 10 as well, so there has to be 10 times an `1` and 10 times an `0`.

I tried to work around it using:

```
$number  = 0;
if ($counter > 0) { 
    $number = 1; 
    $counter--;
}

```

Which worked and is a simple solution but see the 'addition 1`

But this has to be randomized. And each of those positions is in the actual program an array so shuffling the array isn't an option.

TLDR: I need to shuffle only 1 part of an array or have to random generate the `0 or 1` with the given code in the first code sample. And to be honest, I have no idea at this moment how I could do this so any help is appreciated.

Addition 1:

```
array(
      array('I' => 1, 'X' => '7'),  
      array('I' => 1, 'X' => '7'),  
      array('I' => 1, 'X' => 'value'), 
      array('I' => 1, 'X' => 'value'), 
      array('I' => 1, 'X' => 'value'),
      array('I' => 1, 'X' => 'value'),
      array('I' => 1, 'X' => 'value'),
      array('I' => 1, 'X' => 'value'),
      array('I' => 1, 'X' => 'value'),
      array('I' => 1, 'X' => 'value'),
      array('I' => 0, 'X' => 'value'),
      array('I' => 0, 'X' => 'value'),
      array('I' => 0, 'X' => 'value'),
      array('I' => 0, 'X' => 'value'),
      array('I' => 0, 'X' => 'value'),
      array('I' => 0, 'X' => 'value'),
      array('I' => 0, 'X' => 'value'),
      array('I' => 0, 'X' => 'value'),
      array('I' => 0, 'X' => 'value'),
      array('I' => 0, 'X' => 'value'),
);

```

each value can occur 2 times (will not always occur 2 times) and if this is the case one of the 2 value has to be 'I' => 1 and 'I' => 0 but the X is filled with a random as well:

```
$x = rand(1, 100)

```

This is the actual structure sorry if I was unclear with the initial post and now my problem is more clear I presume.

Addition 2:

The expected result:

```
//This is correct
'I' => 1, 'X' => 7
'I' => 0, 'X' => 7

//This is not correct:

'I' => 1, 'X' => 7
'I' => 1, 'X' => 7

//This is not correct
'I' => 0, 'X' => 7
'I' => 0, 'X' => 7

```

* 10 times an 'I' => 1
* 10 times an 'I' => 0
* If an 'X' occurs 2 times see above code sample: