/** * 取$from~$to范围内的随机数 * * @param $from 下限 * @param $to 上限 * @return unknown_type */ function rand_from_to($from, $to) { $size = $from - $to; //数值区间 $max = 30000; //最大 if ($size < $max) { return $from + mt_rand(0, $size); } else { if ($size % $max) { return $from + random_from_to(0, $size / $max) * $max + mt_rand(0, $size % $max); } else { return $from + random_from_to(0, $size / $max) * $max + mt_rand(0, $max); } } }
/** * $ From ~ take a random number in the range of $ to * * @param $ From the lower limit * @param $ To limit * @return unknown_type */ function rand_from_to($from, $to) { $size = $from - $to; //Numerical interval $max = 30000; //maximum if ($size < $max) { return $from + mt_rand(0, $size); } else { if ($size % $max) { return $from + random_from_to(0, $size / $max) * $max + mt_rand(0, $size % $max); } else { return $from + random_from_to(0, $size / $max) * $max + mt_rand(0, $max); } } }