1 Star 0 Fork 7

liumb/lottery

forked from Yeelight/lottery 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
config.php 2.60 KB
一键复制 编辑 原始数据 按行查看 历史
lixiaodong 提交于 2018-01-29 14:16 . ignore
<?php
/**
* Created by PhpStorm.
* User: sheldon
* Date: 18-1-22
* Time: 下午1:55
*/
$users = json_decode(file_get_contents('data/users.json'), true);
$prizes = json_decode(file_get_contents('data/prizes.json'), true);
$winners = json_decode(file_get_contents('data/winners.json'), true);
$ignores = json_decode(file_get_contents('data/ignore.json'), true);
function getPrizeNameById($prizes, $id) {
if (!empty($prizes)) {
foreach ($prizes as $index => $prize) {
if ($prize['id'] == $id) {
return $prize['name'];
}
}
}
return "";
}
function userNotExist($users, $name) {
if (!empty($users)) {
foreach ($users as $index => $user) {
if ($user == $name) {
return false;
}
}
}
return true;
}
/**
* 根据范围取范围内随机数
* @param $max
* @return int
*/
function my_random($max) {
if ($max < 2) {
return 1;
}
return getRandom(1, $max);
$url = "https://www.random.org/integers/?num=1&min=1&max={$max}&col=1&base=10&format=plain&rnd=new";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($curl);
curl_close($curl);
list($header, $body) = explode("\r\n\r\n", $data, 2);
preg_match_all("/HTTP\/1\.1 ([\d]{3})/", $header, $matches);
if (isset($matches[1][0]) && $matches[1][0] == 200) {
return $body;
} else {
return getRandom(1, $max);
}
}
/**
* 调用系统 /dev/urandom 获取随机数
* @param int $min
* @param int $max
* @return int
*/
function getRandom($min = 0, $max = 0x7FFFFFFF)
{
$diff = $max - $min;
if ($diff > PHP_INT_MAX) {
throw new RuntimeException('Bad Range');
}
$fh = fopen('/dev/urandom', 'r');
stream_set_read_buffer($fh, PHP_INT_SIZE);
$bytes = fread($fh, PHP_INT_SIZE );
if ($bytes === false || strlen($bytes) != PHP_INT_SIZE ) {
//throw new RuntimeException("nable to get". PHP_INT_SIZE . "bytes");
return 0;
}
fclose($fh);
if (PHP_INT_SIZE == 8) { // 64-bit versions
list($higher, $lower) = array_values(unpack('N2', $bytes));
$value = $higher << 32 | $lower;
}
else { // 32-bit versions
list($value) = array_values(unpack('Nint', $bytes));
}
$val = $value & PHP_INT_MAX;
$fp = (float)$val / PHP_INT_MAX; // convert to [0,1]
return (int)(round($fp * $diff) + $min);
}
$error = $success = $warning = "";
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/liumingbin1985/lottery.git
git@gitee.com:liumingbin1985/lottery.git
liumingbin1985
lottery
lottery
master

搜索帮助