php function random_num num arr array for if arr rand num-array_sum ar

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
function random_num($num) {
$arr = array();
for ($x = 0; $x < 4; $x++) {
if ($x < 3) {
$arr[] = rand(1, $num-array_sum($arr));
} else {
$arr[] = $num-array_sum($arr);
}
}
return $arr;
}
$s = random_num(350);
echo array_sum($s) . '<br />';
var_dump($s);
/*
1000
array[4]
0 => "328"
1 => "162"
2 => "499"
3 => "11"
*/
?>