- array_rand: documentation ( source)
- asort: documentation ( source)
- array_fill: documentation ( source)
- range: documentation ( source)
<?php
$valeurs = range(1, 40);
$proba = array_fill(1, 40, 0);
for ($i = 0; $i < 10000; ++$i)
{
$tirage_tab = array_rand($valeurs, 10);
foreach($tirage_tab as $key => $value)
{
$proba[$valeurs[$value]]++;
}
}
asort($proba);
echo "Proba : <br/>\n";
foreach($proba as $key => $value)
{
echo "$key : $value<br/>\n";
}