fork download
  1. <?php
  2.  
  3. function myRandom($min, $max, $exclude) {
  4. $random = random_int($min, $max);
  5. if( $random == $exclude) {
  6. return myRandom($min, $max, $exclude);
  7. }
  8. else {
  9. return $random;
  10. }
  11. }
  12.  
  13. for($i = 0; $i < 100; ++$i) {
  14. echo myRandom(1, 6, 3), PHP_EOL;
  15. }
Success #stdin #stdout 0.02s 23780KB
stdin
Standard input is empty
stdout
4
5
6
1
6
6
6
2
1
1
5
4
5
4
6
6
6
6
5
6
6
1
1
6
4
6
2
5
5
6
2
2
6
2
6
4
4
6
1
5
2
2
6
1
1
4
6
1
4
5
4
4
4
4
4
2
2
4
5
4
2
1
1
6
1
6
2
4
5
6
6
1
2
4
2
1
2
4
1
2
6
6
2
4
2
1
5
6
6
1
1
6
4
1
2
4
4
6
1
6