function getRand($count, $sum, $mix, $max){
$i = 1;
while ($i <= $count) {
$tmp[] = mt_rand($mix, $max);
$i++;
}
$k = $sum / array_sum($tmp);
$res = [];
foreach ($tmp as $v) {
$res[] = (int) ($v * $k);
}
$assoc = $sum - array_sum($res);
$last = array_pop($res);
$res[] = $last + $assoc;
while (max($res) > $max) {
$tmax = max($res);
$key = array_search($tmax, $res);
if($key !== false){
$res[$key] = mt_rand($mix, $max);
$k = array_search(min($res), $res);
$res[$k] = $tmax - $res[$key] + min($res);
}
}
return $res;
}