php真随机数-调用random.org接口
// 声明取一个区间内随机数的函数 function getRandom(min = 1,max = 1000) { params = [ 'min' =>min, // 最小数 'max' => max, // 最大数 'num' => 1, // 只取1个随机数 'format' => 'plain', // 返回格式 'col' => 1, // 整数列 填 1 即可 'base' => 10 // 进制数 一般取十进制 ];params_str = http_build_query(params); // 调用 Random.org 的接口ch = curl_init(); url = 'https://www.random.org/integers/?'.params_str; curl_setopt(ch, CURLOPT_URL,url); curl_setopt(ch, CURLOPT_HEADER, 0); curl_setopt(ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt(ch, CURLOPT_SSL_VERIFYPEER, 1);random_info = curl_exec(ch); curl_close(ch); return (int)trim($random_info); }
注意:=> 改成 =>
测试有些许延迟。国外机器或者自己服务器拨vpn可以使用。