PHP random - exception / inclusion / floats / negatives and other animals

I need to create random pairs of numbers (floats) within a specific range. These are mainly points for the pairs [Lat, Lng] (longitude - latitude coordinates)

I thought it would be very easy with

<?php echo (rand(0,60).'.'.rand(0,99999999999999).' ||  '); // yes, a string is ok...?>

but he did not give me control over the number of numbers after the floating point (resolution) that I need.

So the next step:

<?php echo (rand(0,60*pow(10,6)))/pow(10,6).' ||  '; //pow(10,$f) where $ is the resolution ?>

and it works. like .. sometimes it gives results like

22.212346 ||  33.134 ||  36.870757 ||  //(rare , but does happen)

but hey - the coordinates are from -90 to 90 (lon) and from -180 to 180 (lan) - what about the minus?

echo (rand(0,-180*pow(10,9)))/pow(10,9).' ||  ';

which should do this .. and putting everyone together should give me some kind of random string, like

23.0239423525 || -135.937419777

so after all this introduction - here Is my question (s).

  • , , - ? PHP?

  • 3,4 5, , 6 ( ) - php? , ?

  • , "" - - . PHP -- ?

  • ? ( )

, , / ! ( , :-)

+5
1

rand() , , , :

   $num = mt_rand(-180000000, 180000000)/1000000;
   echo number_format($num, 6);

6 .

, , . , . , 3 , . 1 = -180 -10, 2 = 10 - 100 3 = 120 - 180. 1 3 , , , ,

+3

All Articles