<?php
printf("PHP_VERSION=%s\n",PHP_VERSION);
$min = -(mt_getrandmax()>>1);
$max = mt_getrandmax();
$count = isset($argv[1])?(int)$argv[1]:16;
printf("min=%d, max=%d, count=%d\n",$min,$max,$count);
$repeat_counts = array();
for ($i=0;$i<$count;$i++) {
$random = mt_rand($min,$max);
if (!isset($repeat_counts[$random])) {
$repeat_counts[$random] = 0;
}
$repeat_counts[$random]++;
//printf("%12d%s\n", abs($random),($random<0)?"-":"");
}
$max_repeat_count = max($repeat_counts);
$same_value_max = array();
if ($max_repeat_count > 1) {
foreach ($repeat_counts as $value => $repeat_count) {
if ($repeat_count >= $max_repeat_count) {
$same_value_max[] = $value;
}
}
printf("The following number/s was/were repeated %d times (%s%%): %s\n"
,$max_repeat_count
,number_format(($max_repeat_count/$count)*100.0,1)
,implode(", ",$same_value_max)
);
}
preferences:
32.04 ms | 402 KiB | 5 Q