lundi 22 mai 2017

Cannot Redeclare Random Floats Error

PHP beginner here and I am trying to use the code below to generate 5 random floats and then add them together. However, keep running in to a "Cannot Redeclare" error. Any help or suggestions? Thanks!

function RandRoll($mod1, $mod2){

    $modCalc = 1.00 + $mod1 + $mod2;
    echo "(" . $modCalc . ")"; 

    $RAND_MIN = $modCalc;
    $RAND_MAX = 100.00;


    function frand($min, $max, $decimals = 0) {
      $scale = pow(10, $decimals);
      return mt_rand($min * $scale, $max * $scale) / $scale;
    }

    $result = frand($RAND_MIN, $RAND_MAX, 2);

    return $result;
}

$moda1 = 23.45;
$moda2 = 17.21;
$score1 = RandRoll($moda1, $moda2);
$score2 = RandRoll($moda1, $moda2);
$score3 = RandRoll($moda1, $moda2);
$score4 = RandRoll($moda1, $moda2);
$score5 = RandRoll($moda1, $moda2);

echo $score1 + $score2 + $score3 + $score4 + $score5;




Aucun commentaire:

Enregistrer un commentaire