@ 2017-12-02T09:39:04Z <?php
//
function random_number_with_dupe($len = 6, $dup = 1, $sort = false) {
$num = range(0,9);
shuffle($num);
$num = array_slice($num, 0, ($len-$dup)+1);
if ($dup > 0) {
$k = array_rand($num, 1);
for ($i=0;$i<($dup-1);$i++) {
$num[] = $num[$k];
}
}
if ($sort) {
sort($num);
}
return implode('', $num);
}
echo '4 unique and 2 repetitive digits.'.PHP_EOL;
for ($i=0; $i<5; $i++) {
echo random_number_with_dupe(6, 2, true).PHP_EOL;
}
/*
4 unique and 2 repetitive digits.
235699
037789
034677
012249
033569
*/
echo '3 unique and 3 repetitive digits.'.PHP_EOL;
for ($i=0; $i<5; $i++) {
echo random_number_with_dupe(6, 3, true).PHP_EOL;
}
/*
3 unique and 3 repetitive digits.
015559
011147
111239
677789
456777
*/
echo '2 unique and 4 repetitive digits.'.PHP_EOL;
for ($i=0; $i<5; $i++) {
echo random_number_with_dupe(6, 4, true).PHP_EOL;
}
/*
2 unique and 4 repetitive digits.
068888
022229
018888
333378
000058
*/
echo '1 unique and 5 repetitive digits.'.PHP_EOL;
for ($i=0; $i<5; $i++) {
echo random_number_with_dupe(6, 5, true).PHP_EOL;
}
/*
1 unique and 5 repetitive digits.
788888
066666
799999
355555
244444
*/
echo '0 unique and 6 repetitive digits.'.PHP_EOL;
for ($i=0; $i<5; $i++) {
echo random_number_with_dupe(6, 6, true).PHP_EOL;
}
/*
0 unique and 6 repetitive digits.
888888
333333
777777
888888
777777
*/
echo 'All rules.'.PHP_EOL;
for ($i=0; $i<6; $i++) {
echo random_number_with_dupe(6, $i+1, true).PHP_EOL;
}
/*
All rules.
345789
003569
245666
000089
777778
555555
*/
echo 'All rules (random).'.PHP_EOL;
for ($i=0; $i<6; $i++) {
echo random_number_with_dupe(6, mt_rand(1, 6), true).PHP_EOL;
}
/*
All rules (random).
225678
222222
111359
444444
777778
233349
*/
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.3.1 0.013 0.000 16.33 7.3.0 0.009 0.006 16.23 7.2.13 0.009 0.006 16.89 7.2.12 0.016 0.009 16.29 7.2.11 0.016 0.010 16.60 7.2.10 0.007 0.011 16.51 7.2.9 0.012 0.006 16.66 7.2.8 0.004 0.015 16.41 7.2.7 0.007 0.007 16.61 7.2.6 0.006 0.009 17.05 7.2.5 0.007 0.007 16.49 7.2.4 0.016 0.003 16.30 7.2.3 0.011 0.007 16.64 7.2.2 0.006 0.012 16.71 7.2.1 0.013 0.013 16.66 7.2.0 0.010 0.009 17.09 7.1.25 0.007 0.015 15.39 7.1.12 0.003 0.012 17.17 7.1.11 0.006 0.016 16.57 7.1.10 0.011 0.009 16.21 7.1.9 0.015 0.012 16.40 7.1.8 0.014 0.014 16.18 7.1.7 0.008 0.016 15.41 7.1.6 0.035 0.009 33.33 7.1.5 0.028 0.021 32.96 7.1.4 0.026 0.013 32.57 7.1.3 0.024 0.021 32.78 7.1.2 0.025 0.018 32.93 7.1.1 0.003 0.016 14.59 7.1.0 0.009 0.014 14.94 7.0.26 0.012 0.012 16.71 7.0.25 0.015 0.006 16.08 7.0.24 0.010 0.006 16.22 7.0.23 0.010 0.010 15.71 7.0.22 0.006 0.012 15.75 7.0.21 0.064 0.012 14.89 7.0.20 0.013 0.012 15.13 7.0.19 0.011 0.007 14.86 7.0.18 0.003 0.017 14.57 7.0.17 0.006 0.019 14.47 7.0.16 0.008 0.016 14.57 7.0.15 0.004 0.011 14.57 7.0.14 0.012 0.004 14.52 7.0.13 0.007 0.010 14.69 7.0.12 0.027 0.014 14.54 7.0.11 0.016 0.007 14.62 7.0.10 0.011 0.011 14.51 7.0.9 0.007 0.007 14.48 7.0.8 0.006 0.013 14.54 7.0.7 0.009 0.006 14.74 7.0.6 0.007 0.013 14.52 7.0.5 0.006 0.016 14.65 7.0.4 0.000 0.018 14.77 7.0.3 0.009 0.013 14.94 7.0.2 0.018 0.000 14.54 7.0.1 0.006 0.018 14.79 7.0.0 0.003 0.020 14.59
preferences:dark mode live preview ace vim emacs key bindings
27.25 ms | 403 KiB | 5 Q