在PHP

时间:2015-09-23 17:10:06

标签: php random

我想在我看来做一个相当乏味的任务,因为我是php及其框架的新手。我被困在试图计算两点之间的分配点。完成之后,我想在这些点之间获得任意随机数,然后将其添加回给定输入。因此,例如,如果用户输入89.56作为振幅基数,-22.4作为长基数,并假设5是两个点的距离。我想首先计算一个弧度和长底之间的中点。 (我已经在我的代码中完成了)。接下来我想在中点和距离之间得到一个随机数(我已经这样做但我觉得它有问题)。最后我想在距离和中点之间输出随机数,然后在下面的代码中将该值添加到$ peter。所以我的问题在于两个部分:生成随机数并获得要输出的随机数。以下是我的代码:

<!DOCTYPE html>
   <head> 

      <title> Distance </title>
   </head>

   <body>

   <?php


  function distance($lat,$lng,$d){

      if($d != 0)
    {
   $distannce = ($lat - $lng) / 50.732;
   }
   else
   {
   $distannce = 0;
    }

    return $distannce;

    }  

     function generaterandom($t,$e){
    $min = $t;
    $max = $e;

   $star = rand($min,$max);

}

  function uniform($g,$s,$r){ //
 // %g is already the distance.. Find a way to get the lat and long and then get the midpoint then do the math

     $clap = getmidpoint($s,$r);

     $zone = generaterandom($g,$clap);


     $ta = $g - $s;  

     $la = $g + $s;

     $ga =  1 /($la - $ta ); 




 $sub = ($ga)*($zone);

 return $sub;
  }

  function getmidpoint($x,$y){
  $midpoint = ($x + $y)/2;

  }

$stand =       distance(isset($_POST['val']),isset($_POST['value']),isset($_POST['dist']));


   if (isset($_POST['dtMAX'])&& isset($_POST['dtLatLng_Lat'])) { // if the max radio button is selected and latitude is selected do math

$peter = uniform($stand,$_POST['val'], $_POST['value']);

   }

  else if (isset($_POST['dtMAX'])&& isset($_POST['dtLatLng'])) { // if max radio buttion is selected and longitude do math

   $peter = uniform($stand,$_POST['value'],$_POST['val']);

 }

    //This statement below says if everything is fine do all the functions and print


    if(isset($_POST['submit'])) {
    if(!empty($peter)){

    if (isset($_POST['dtMAX'])&& isset($_POST['dtLatLng_Lat'])){

    echo ($peter + $_POST['val']); 
    //echo out your final result

   }
    else if (isset($_POST['dtSTD'])&& isset($_POST['dtLatLng'])){

     echo ($peter + $_POST['value']); 

  }

     }
    else {
     echo "You need to check your input";   // if there is nothing in the input output this statement
      }

    }

?>
  <form method = "post">



  <input type="checkbox" name="dtLatLng_Lat"  checked="checked"  />
   <label for="dtLatLng_Lat"> Lat </label>&nbsp &nbsp &nbsp;
   base
   <input type="text"name="val"  size ="6"   style="width:60px"; /> 

    dist
   <input type="text"name="dis" id="dis" size = "1"; /> 
    <label for="dis">  </label>
    <br>

  <input type="checkbox" name="dtLatLng" id="dtLatLng" checked="checked" />
  <label for="dtLatLng"> Long </label>&nbsp &nbsp;
  base
   <input type="text" name="value" id="dtvalue" size ="6" style="width:60px";/> 
    <label for="dtvalue"> </label>&nbsp;

  dist
<input type="text"name="dist" id="dtval" size ="1"; /> 

  <br>
   Options:         
<input type="radio" name="dtMAX" id="dtMAX" />
<label for="dtMAX"> Maxium </label>



 <br>
  <input type="submit" name="submit" value="Submit" />

   </form>
  </body>
    </html>


I created an output statement to test to see if nothing has been inputted and each time whenever i enter some value, the statement is outputted " check your input" can someone guide me in the right direction. Well an explanation as to what i am doing wrong. Thanks in advance

1 个答案:

答案 0 :(得分:1)

您在生成随机函数中缺少返回值