取任意2个数,生成这两个数之间的随机数,包括小数。
$u[0]=74.3;//设置起始数值 $u[1]=74.45;//设置终止数值
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>随机数</title> <style type="text/css"> <!-- * {margin:0 auto; } body,table{line-height:1;font:14px “Podkova”,”微软雅黑”,Arial,Tahoma,Verdana,Helvetica,sans-serif;color:#000;} form, table, input, textarea, dl, dt, dd{outline:none} .head td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#e9e9e9;padding:5px 10px 5px 5px;font-weight:bold;} .head td span{font-weight:normal;} a{color:black;text-decoration:none;font:14px Verdana;} a:hover{color:red;text-decoration:none;} .line { font-size: 0px; border-top-width: 1px; border-top-style: solid; border-top-color: #CCCCCC; padding: 0px; margin-top: 1px; margin-right: 0px; margin-bottom: 1px; margin-left: 0px;} .con {width: 800px;margin-top: 5px;margin-right: auto;margin-left: auto;align: left;} --> </style> </head> <body> <center> <div class="con" align="left"> <a href="rand.php">刷新</a> <div class="line"></div> <?php function _getFloatLength($num) { $count = 0; $temp = explode ('.', $num); if (sizeof ($temp) > 1) { $decimal = end ($temp); $count = strlen ($decimal); } return $count; } // 调试函数 function pr($a) { echo '<pre>'; print_r($a); echo '</pre>'; } function rand_ ($l,$u,$ll){ $bs=pow(10,$ll); //echo $bs.'<br>'.$l*$bs.'<br>'.$u*$bs.'<br><br><br>'; for ($i=1;$i<=200;$i++){ if($i>5 && ($i%5) ==1){echo "<br>";} else { if ($i>1) {echo ",";} } echo rand($l*$bs,$u*$bs)/$bs; } } $u=Array(); $u[0]=74.3; $u[1]=74.45; $u[2]=_getFloatLength($u[0]); $u[3]=_getFloatLength($u[1]); $u[4]=max($u[2],$u[3]); //pr($u); rand_($u[0],$u[1],$u[4]); ?> </div> </center> </body> </html>