<?php
$total = 400;
$count = 45;
$numbers = [];
do {
$random = mt_rand(1, 1000);
if (!array_key_exists($random, $numbers)) {
$numbers[$random] = $random;
}
} while (sizeof($numbers) < $count);
$sum = array_sum($numbers);
foreach ($numbers as $k => $v) {
$numbers[$k] = $total * $v / $sum;
}
print_r($numbers);
print_r(array_sum($numbers));
Array
(
[192] => 3.0298248382515
[993] => 15.669875335332
[291] => 4.592078270475
[695] => 10.967334700963
[718] => 11.330282468045
[386] => 6.0912103519015
[400] => 6.3121350796907
[751] => 11.851033612119
[507] => 8.000631213508
[206] => 3.2507495660407
[933] => 14.723055073379
[872] => 13.760454473726
[711] => 11.21982010415
[890] => 14.044500552312
[224] => 3.5347956446268
[659] => 10.39924254379
[899] => 14.186523591605
[67] => 1.0572826258482
[948] => 14.959760138867
[976] => 15.401609594445
[140] => 2.2092472778917
[399] => 6.2963547419915
[492] => 7.7639261480196
[812] => 12.813634211772
[572] => 9.0263531639577
[561] => 8.8527694492662
[834] => 13.160801641155
[534] => 8.4267003313871
[873] => 13.776234811425
[143] => 2.2565882909894
[768] => 12.119299353006
[342] => 5.3968754931356
[354] => 5.5862395455263
[202] => 3.1876282152438
[716] => 11.298721792646
[811] => 12.797853874073
[701] => 11.062016727158
[987] => 15.575193309137
[669] => 10.557045920783
[513] => 8.0953132397033
[706] => 11.140918415654
[242] => 3.8188417232129
[440] => 6.9433485876598
[171] => 2.6984377465678
[48] => 0.75745620956288
)
400
<?php
$dataset = [
[0, 1, 2, 3, 4, 5],
[0, 1, 2, 3, 6, 7, 8, 9, 12, 13, 14, 15],
[94, 95],
[0, 1, 94, 95],
];
function arrange($array)
{
$groups = [];
$group = null;
foreach ($array as $index => $current) {
if ($group === null) {
$group = [
'start' => $current,
'end' => $current
];
continue;
}
$group['end'] = $current;
$next = $index + 1;
if (array_key_exists($next, $array)) {
if ($array[$next] - $current !== 1) {
array_push($groups, $group);
$group = null;
}
}
}
if ($group !== null) {
array_push($groups, $group);
}
return $groups;
}
foreach ($dataset as $array) {
$arrange = arrange($array);
print_r($arrange);
}
(x1 * x2 + y1 * y2) / Math.sqrt(Math.pow(x1, 2) + Math.pow(y1, 2)) * Math.sqrt(Math.pow(x2, 2) + Math.pow(y2, 2))
(x1 * x2 + y1 * y2) / Math.sqrt(Math.pow(x1, 2) + Math.pow(y1, 2)) / Math.sqrt(Math.pow(x2, 2) + Math.pow(y2, 2))