3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Returns N±(0~n/m) randomness * * @param $n int Base number * @param $m int Fraction of number to use for random/ * * @return float */ function addRandomToN($n, $m) { $plus = mt_rand(0,1); if ($plus) { return $n + (($n/$m) * rand0To1()); } return $n - (($n/$m) * rand0To1()); } function rand0To1() { return (float)rand()/(float)getrandmax(); } echo addRandomToN(5, 0.1);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RGDi3
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                               'addrandomton'
          1        SEND_VAL                                                 5
          2        SEND_VAL                                                 0.1
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
          5      > RETURN                                                   1

Function addrandomton:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RGDi3
function name:  addRandomToN
number of ops:  21
compiled vars:  !0 = $n, !1 = $m, !2 = $plus
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        INIT_FCALL                                               'mt_rand'
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 1
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !2, $3
   13     7      > JMPZ                                                     !2, ->14
   14     8    >   DIV                                              ~5      !0, !1
          9        INIT_FCALL_BY_NAME                                       'rand0To1'
         10        DO_FCALL                                      0  $6      
         11        MUL                                              ~7      $6, ~5
         12        ADD                                              ~8      !0, ~7
         13      > RETURN                                                   ~8
   16    14    >   DIV                                              ~9      !0, !1
         15        INIT_FCALL_BY_NAME                                       'rand0To1'
         16        DO_FCALL                                      0  $10     
         17        MUL                                              ~11     $10, ~9
         18        SUB                                              ~12     !0, ~11
         19      > RETURN                                                   ~12
   18    20*     > RETURN                                                   null

End of function addrandomton

Function rand0to1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RGDi3
function name:  rand0To1
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                               'rand'
          1        DO_ICALL                                         $0      
          2        CAST                                          5  ~1      $0
          3        INIT_FCALL                                               'getrandmax'
          4        DO_ICALL                                         $2      
          5        CAST                                          5  ~3      $2
          6        DIV                                              ~4      ~1, ~3
          7      > RETURN                                                   ~4
   22     8*     > RETURN                                                   null

End of function rand0to1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.92 ms | 1403 KiB | 20 Q