3v4l.org

run code in 300+ PHP versions simultaneously
<?php function random_float($min, $max) { return random_int($min, $max - 1) + (random_int(0, PHP_INT_MAX - 1) / PHP_INT_MAX ); } function generateRandomNumbers($max, $count){ $randoms = []; for ($i=0; $i <$count ; $i++) { if($i>0) { while(1){ $this_random = random_float(0.1,$max); if(!in_array($this_random,$randoms)) { $randoms[] = $this_random; break; } } } else { $this_random = random_float(0.1,$max); $randoms[] = $this_random; } } $numbers = []; $sum_of_randoms = array_sum($randoms); foreach ($randoms as $key => $value) { $numbers[] = ($value/$sum_of_randoms) * $max; } return $numbers; } echo array_sum(generateRandomNumbers(10,20)); echo '<pre>'; print_r(generateRandomNumbers(10,20)); echo '</pre>'; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IKhOJ
function name:  (null)
number of ops:  18
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   INIT_FCALL                                               'array_sum'
          1        INIT_FCALL                                               'generaterandomnumbers'
          2        SEND_VAL                                                 10
          3        SEND_VAL                                                 20
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                         $1      
          7        ECHO                                                     $1
   36     8        ECHO                                                     '%3Cpre%3E'
   37     9        INIT_FCALL                                               'print_r'
         10        INIT_FCALL                                               'generaterandomnumbers'
         11        SEND_VAL                                                 10
         12        SEND_VAL                                                 20
         13        DO_FCALL                                      0  $2      
         14        SEND_VAR                                                 $2
         15        DO_ICALL                                                 
   38    16        ECHO                                                     '%3C%2Fpre%3E'
   39    17      > RETURN                                                   1

Function random_float:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IKhOJ
function name:  random_float
number of ops:  15
compiled vars:  !0 = $min, !1 = $max
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        INIT_FCALL                                               'random_int'
          3        SEND_VAR                                                 !0
          4        SUB                                              ~2      !1, 1
          5        SEND_VAL                                                 ~2
          6        DO_ICALL                                         $3      
          7        INIT_FCALL                                               'random_int'
          8        SEND_VAL                                                 0
          9        SEND_VAL                                                 9223372036854775806
         10        DO_ICALL                                         $4      
         11        DIV                                              ~5      $4, 9223372036854775807
         12        ADD                                              ~6      $3, ~5
         13      > RETURN                                                   ~6
    4    14*     > RETURN                                                   null

End of function random_float

Function generaterandomnumbers:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 5
Branch analysis from position: 34
2 jumps found. (Code = 77) Position 1 = 40, Position 2 = 47
Branch analysis from position: 40
2 jumps found. (Code = 78) Position 1 = 41, Position 2 = 47
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 24
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 8
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 5
Branch analysis from position: 34
Branch analysis from position: 5
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 22
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 5
Branch analysis from position: 34
Branch analysis from position: 5
filename:       /in/IKhOJ
function name:  generateRandomNumbers
number of ops:  50
compiled vars:  !0 = $max, !1 = $count, !2 = $randoms, !3 = $i, !4 = $this_random, !5 = $numbers, !6 = $sum_of_randoms, !7 = $value, !8 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        ASSIGN                                                   !2, <array>
    9     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->32
   10     5    >   IS_SMALLER                                               0, !3
          6      > JMPZ                                                     ~11, ->24
   12     7    > > JMP                                                      ->22
   13     8    >   INIT_FCALL                                               'random_float'
          9        SEND_VAL                                                 0.1
         10        SEND_VAR                                                 !0
         11        DO_FCALL                                      0  $12     
         12        ASSIGN                                                   !4, $12
   14    13        INIT_FCALL                                               'in_array'
         14        SEND_VAR                                                 !4
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $14     
         17        BOOL_NOT                                         ~15     $14
         18      > JMPZ                                                     ~15, ->22
   16    19    >   ASSIGN_DIM                                               !2
         20        OP_DATA                                                  !4
   17    21      > JMP                                                      ->23
   12    22    > > JMPNZ                                                    1, ->8
   10    23    > > JMP                                                      ->31
   22    24    >   INIT_FCALL                                               'random_float'
         25        SEND_VAL                                                 0.1
         26        SEND_VAR                                                 !0
         27        DO_FCALL                                      0  $17     
         28        ASSIGN                                                   !4, $17
   23    29        ASSIGN_DIM                                               !2
         30        OP_DATA                                                  !4
    9    31    >   PRE_INC                                                  !3
         32    >   IS_SMALLER                                               !3, !1
         33      > JMPNZ                                                    ~21, ->5
   26    34    >   ASSIGN                                                   !5, <array>
   27    35        INIT_FCALL                                               'array_sum'
         36        SEND_VAR                                                 !2
         37        DO_ICALL                                         $23     
         38        ASSIGN                                                   !6, $23
   28    39      > FE_RESET_R                                       $25     !2, ->47
         40    > > FE_FETCH_R                                       ~26     $25, !7, ->47
         41    >   ASSIGN                                                   !8, ~26
   29    42        DIV                                              ~29     !7, !6
         43        MUL                                              ~30     !0, ~29
         44        ASSIGN_DIM                                               !5
         45        OP_DATA                                                  ~30
   28    46      > JMP                                                      ->40
         47    >   FE_FREE                                                  $25
   31    48      > RETURN                                                   !5
   32    49*     > RETURN                                                   null

End of function generaterandomnumbers

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.95 ms | 1451 KiB | 21 Q