Возможно что-то вроде этого?
<?php
function random_swap_array($array, $scale=10) {
$max = sizeof($array) - 1;
for ($i=0; $i<$scale; $i++) {
$pos1 = random_int(0, $max);
$pos2 = random_int(0, $max);
// swap the value of 2 pos
$tmp = $array[$pos2];
$array[$pos2] = $array[$pos1];
$array[$pos1] = $tmp;
}
return $array;
}
function gen_n(int $n, $value) {
for ($i=0; $i<$n; $i++) yield $value;
}
function gen_prefix_num(int $n, $prefix) {
for ($i=1; $i<=$n; $i++) yield "{$prefix}{$i}";
}
// This generates an assoc array with key "Test1" to "Test18"
// and values of randomly placed 14 "P" and 4 "F"
$arr = array_combine(
iterator_to_array(gen_prefix_num(18, 'Test')),
random_swap_array(array_merge(
iterator_to_array(gen_n(4, 'F')),
iterator_to_array(gen_n(14, 'P'))
), 100)
);
var_dump($arr); // display results
Результат:
array(18) {
["Test1"]=>
string(1) "P"
["Test2"]=>
string(1) "F"
["Test3"]=>
string(1) "P"
["Test4"]=>
string(1) "P"
["Test5"]=>
string(1) "P"
["Test6"]=>
string(1) "P"
["Test7"]=>
string(1) "P"
["Test8"]=>
string(1) "P"
["Test9"]=>
string(1) "F"
["Test10"]=>
string(1) "P"
["Test11"]=>
string(1) "P"
["Test12"]=>
string(1) "P"
["Test13"]=>
string(1) "P"
["Test14"]=>
string(1) "F"
["Test15"]=>
string(1) "P"
["Test16"]=>
string(1) "P"
["Test17"]=>
string(1) "F"
["Test18"]=>
string(1) "P"
}