3v4l.org

run code in 300+ PHP versions simultaneously
<?php function generateRandomNumber($min = 0, $max = PHP_INT_MAX) { $range = max($max, $min) - min($max, $min); if (0 == $range) { throw new \Exception('Cannot create a random number with range = 0 ($min and $max are the same).'); } $byteLength = (int) (log($range, 2) / 8) + 1; $random = hexdec(bin2hex(openssl_random_pseudo_bytes($byteLength))) % $range; return $min + $random; } echo generateRandomNumber();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6kiie
function name:  (null)
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                               'generaterandomnumber'
          1        DO_FCALL                                      0  $0      
          2        ECHO                                                     $0
          3      > RETURN                                                   1

Function generaterandomnumber:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6kiie
function name:  generateRandomNumber
number of ops:  40
compiled vars:  !0 = $min, !1 = $max, !2 = $range, !3 = $byteLength, !4 = $random
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV_INIT                                        !0      0
          1        RECV_INIT                                        !1      <const ast>
    5     2        INIT_FCALL                                               'max'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $5      
          6        INIT_FCALL                                               'min'
          7        SEND_VAR                                                 !1
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $6      
         10        SUB                                              ~7      $5, $6
         11        ASSIGN                                                   !2, ~7
    6    12        IS_EQUAL                                                 !2, 0
         13      > JMPZ                                                     ~9, ->18
    7    14    >   NEW                                              $10     'Exception'
         15        SEND_VAL_EX                                              'Cannot+create+a+random+number+with+range+%3D+0+%28%24min+and+%24max+are+the+same%29.'
         16        DO_FCALL                                      0          
         17      > THROW                                         0          $10
   10    18    >   INIT_FCALL                                               'log'
         19        SEND_VAR                                                 !2
         20        SEND_VAL                                                 2
         21        DO_ICALL                                         $12     
         22        DIV                                              ~13     $12, 8
         23        CAST                                          4  ~14     ~13
         24        ADD                                              ~15     ~14, 1
         25        ASSIGN                                                   !3, ~15
   11    26        INIT_FCALL                                               'hexdec'
         27        INIT_FCALL                                               'bin2hex'
         28        INIT_FCALL_BY_NAME                                       'openssl_random_pseudo_bytes'
         29        SEND_VAR_EX                                              !3
         30        DO_FCALL                                      0  $17     
         31        SEND_VAR                                                 $17
         32        DO_ICALL                                         $18     
         33        SEND_VAR                                                 $18
         34        DO_ICALL                                         $19     
         35        MOD                                              ~20     $19, !2
         36        ASSIGN                                                   !4, ~20
   13    37        ADD                                              ~22     !0, !4
         38      > RETURN                                                   ~22
   14    39*     > RETURN                                                   null

End of function generaterandomnumber

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.69 ms | 1403 KiB | 24 Q