{% else-1 %}
Рандом с зависимостью

                        
<?php

function randomChoose(array $array)
{
$randomChance = mt_rand(0, array_sum($array));
$chances = 0;
foreach ($array as $value => $chance) {
$chances += $chance;
if ($randomChance <= $chances) {
return $value;
}
}
}

var_dump(randomChoose([
'а' => 10,
'б' => 15,
'в' => 25,
'г' => 50,
]));
0 62 0
Без комментариев...