3v4l.org

run code in 300+ PHP versions simultaneously
<?php function roll ($probability, $precision = 5) { return mt_rand(1, pow(10, $precision) / $probability); } $rolls = array(); for ($i = 0; $i < 500; $i++) { $rolls[roll(0.25)]++; } var_dump($rolls);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 3
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 3
Branch analysis from position: 11
Branch analysis from position: 3
filename:       /in/QttI9
function name:  (null)
number of ops:  15
compiled vars:  !0 = $rolls, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ASSIGN                                                   !0, <array>
    9     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->9
   10     3    >   INIT_FCALL                                               'roll'
          4        SEND_VAL                                                 0.25
          5        DO_FCALL                                      0  $4      
          6        FETCH_DIM_RW                                     $5      !0, $4
          7        PRE_INC                                                  $5
    9     8        PRE_INC                                                  !1
          9    >   IS_SMALLER                                               !1, 500
         10      > JMPNZ                                                    ~8, ->3
   13    11    >   INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function roll:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QttI9
function name:  roll
number of ops:  13
compiled vars:  !0 = $probability, !1 = $precision
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      5
    4     2        INIT_FCALL                                               'mt_rand'
          3        SEND_VAL                                                 1
          4        INIT_FCALL                                               'pow'
          5        SEND_VAL                                                 10
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $2      
          8        DIV                                              ~3      $2, !0
          9        SEND_VAL                                                 ~3
         10        DO_ICALL                                         $4      
         11      > RETURN                                                   $4
    5    12*     > RETURN                                                   null

End of function roll

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.55 ms | 1399 KiB | 20 Q