php function expRand num parts array array for parts if parts limit nu

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
function expRand($num, $parts){
$array = array();
for ($i = 1; $i <= $parts; $i++) {
if ($i != $parts) {
$limit = $num * 0.8;
$newRest = mt_rand(0, $limit);
}else{
$newRest = $num;
}
$num -= $newRest;
array_push($array, $newRest);
}
return $array;
}
print_r(expRand(350, 4));
?>