function getPrize($prize_arr) { /*$prize_arr = array( '0' => array('id' =>1,'min' =>1,'max' =>29,'content' =>'一等奖','v' =>2,'num'=>10), '1' => array('id' =>2,'min' =>302,'max' =>328, 'content' =>'二等奖','v' =>5,'num'=>8), '2' => array('id' =>3,'min' =>242,'max' =>268, 'content' =>'三等奖','v' =>10,'num'=>5), '3' => array('id' =>4,'min' =>182,'max' =>208, 'content' =>'四等奖','v' =>50,'num'=>3), '4' => array('id' =>5,'min' =>122, 'max' =>148, 'content' =>'五等奖','v' =>100,'num'=>2), '5' => array('id' =>6,'min' =>62, 'max' =>88, 'content' =>'六等奖','v' =>490,'num'=>1), '6' => array('id' =>7,'min' =>array(32, 92, 152, 212, 272, 332),'max' =>array(58, 118, 178, 238, 298, 358), 'content' =>'谢谢参与' , 'v' =>600,'num'=>0) );*/ foreach ($prize_arr as $key => $val) { $arr[$val['id']] = $val['v']; } $rid = getRand($arr); //根据概率获取奖项 id $res = $prize_arr[$rid - 1]; //中奖项 /*$min = $res['min' ]; $max = $res['max' ]; if($res['id']==7){ //七等奖 $i = mt_rand(0, 5); $result['angle' ] = mt_rand($min[$i], $max[$i]); } else{ $result['angle' ] = mt_rand($min, $max); //随机生成一个角度 } $result['content' ] = $res['content']; $result['id']=$res['id']; $result['num']=$res['num'];*/ $res['sncode'] = strtoupper(substr(md5(time()), mt_rand(1, 18), 15)); return $res; }
$db->query($insert_sql); } $ck_prize_num = $db->getOne("SELECT `user_count` FROM `wxch_prize_cnum` WHERE `paid` = '{$v['id']}'"); if ($ck_prize_num >= $v['prize_value']) { if ($prize_arr[$k]['state'] == 'yes') { unset($prize_arr[$k]); } } } foreach ($prize_arr as $key => $val) { if (!empty($val['prize_value'])) { $arr[$val['id']] = $val['prize_value']; } } $fun = 'egg'; $rid = getRand($arr); $wxid = $_GET['wxid']; $query_sql = "SELECT `count` FROM `wxch_prize_count` WHERE `wxid` = '{$wxid}' AND `pid` = '{$pid}'"; $res['num'] = $db->getOne("SELECT `num` FROM `wxch_prize` WHERE `pid` = '{$pid}' "); $prize_count = $db->getOne($query_sql); //用户剩余积分 $query_sql1 = "SELECT `pay_points` FROM `ecs_users` WHERE `wxid` = '{$wxid}' "; $user_point = $db->getOne($query_sql1); //每次金蛋扣除积分 $prize['point'] = $db->getOne("SELECT `point` FROM `wxch_prize` WHERE `pid` = '{$pid}' "); if ($prize_count >= $res['num']) { $res['msg'] = 2; $res['prize'] = '您抽奖的机会用完了'; $res['num'] = 0; echo json_encode($res); exit;
<?php include 'lxapi/webApi.php'; $smarty = LxWeb::_Temp(); $db = middle::load('mysql'); //加载middle中的load自动加载方法 $db->loadSql('db1', 1); $count = $db->table('a_tmall_wx')->count(); $page = middle::load('page'); $page->setConf($count, 20, 'page/', 5); $page_data = $page->showpage(); $arcList = $db->table('a_tmall_wx')->order('id desc')->setFiles(array('title', 'id', 'shop_title', 'createtime', 'shop_pic'))->limit($page->limit)->selectAll(); $rightFirst = getRand(15); $smarty->assign('rightFirst', $rightFirst); $smarty->assign('arcli', $arcList); $smarty->assign('page_data', $page_data); $smarty->display('index.html'); function getRand($limit = 10) { global $db; $arcList = $db->table('a_tmall_wx')->setFiles(array('title', 'id', 'shop_title', 'shop_pic'))->order('rand()')->limit($limit)->selectAll(); return $arcList; }
/** * 更新用户登录信息 * @param integer $uid 用户ID */ protected function updateLogin($uid) { $data = array('id' => $uid, 'last_login_time' => NOW_TIME, 'last_login_ip' => get_client_ip(1), 'sessid' => getRand()); $this->save($data); }
static function flush($rand = false) { if (!self::$db) { self::connect(); } if (self::$type == 'memcache') { return self::$db->flush(); } else { if (!$rand || $rand && getRand(array(0.999, 0.001), 3)) { M(self::$db)->delete('cache_time < ' . TIME); } } return true; }
exit; } if ($count >= $config['mm']) { echo json_encode(array('status' => 3)); exit; } if ($config['extnum'] > getuserprofile('extcredits' . $config['extcredit'])) { echo json_encode(array('status' => 4)); exit; } $ext = 'extcredits' . $config['extcredit']; $count = C::t('#aljwsq#aljwsq_ggk_log')->count_by_uid_dateline($_G['uid']); foreach ($prize_arr as $key => $val) { $arr[$val['id']] = $val['v']; } $rid = getRand($arr, $rids); $res = $prize_arr[$rid]; if ($rid != 0) { $result['status'] = 88; } else { $result['status'] = 0; $prize_arr[$rid]['prize'] = lang('plugin/aljwsq', 'ggk1'); } $result['prize'] = diconv($prize_arr[$rid]['prize'], CHARSET, 'utf-8'); if ($prize_arr[$rid]['prize']) { updatemembercount($_G['uid'], array($config['extcredit'] => intval('-' . $config['extnum']))); if ($prize_arr[$rid]['extcredit'] != 0) { updatemembercount($_G['uid'], array($config['extcredit'] => $prize_arr[$rid]['extcredit'])); } C::t('#aljwsq#aljwsq_ggk_log')->insert(array('uid' => $_G['uid'], 'username' => $_G['username'], 'dateline' => $_G['timestamp'], 'isnot' => $prize_arr[$rid]['extcredit'], 'rid' => $rid, 'reward' => $prize_arr[$rid]['prize'], 'prizename' => $prize_arr[$rid]['prizename'])); }
<?php function getRand($n) { $max = $n + 1; $bigend = (1 + $max) * $max / 2; $rand = rand(); $x = abs(intval($rand) % $bigend); $sum = 0; for ($i = 1; $i < $max; $i++) { $sum += $max - $i; if ($sum > $x) { return $i; } } return 1; } echo getRand(5);
$data = ''; $proSum = array_sum($proArr); foreach ($proArr as $k => $v) { $randNum = mt_rand(1, $proSum); //echo $randNum.'=>'.$v.'<br>'; if ($randNum <= $v) { $data = $k; break; } else { $proSum -= $v; } } unset($proArr); return $data; } //prize表示奖项内容, angle表示奖项对应角度,v表示中奖几率(若数组中每个奖项的v的总和为100,如果v的值为1,则代表中奖几率为1%,依此类推) $prize_arr = array('0' => array('id' => 1, 'prize' => '一等奖', 'angle' => 0 + 10 * 360, 'v' => 1), '1' => array('id' => 2, 'prize' => '二等奖', 'angle' => 120 + 10 * 360, 'v' => 2), '2' => array('id' => 3, 'prize' => '三等奖', 'angle' => 240 + 10 * 360, 'v' => 7), '3' => array('id' => 4, 'prize' => '再接再厉', 'angle' => 150 + 10 * 360, 'v' => 10), '4' => array('id' => 5, 'prize' => '要加油哦', 'angle' => 265 + 10 * 360, 'v' => 15), '5' => array('id' => 6, 'prize' => '谢谢参与', 'angle' => 330 + 10 * 360, 'v' => 65)); foreach ($prize_arr as $k => $v) { $arr[$v['id']] = $v['v']; } $prize_id = getRand($arr); $res = $prize_arr[$prize_id - 1]; //中奖项 $data['id'] = $res['id']; $data['prize'] = $res['prize']; $data['angle'] = $res['angle']; echo json_encode($data); ?>
if (isset($_POST['submit'])) { include_once 'connect.php'; $n = $_POST['fname']; $e = $_POST['email']; $m = $_POST['mob']; $d = $_POST['dob']; $p = $_POST['pwd']; $g = $_POST['gend'] == 'm' ? 'Male' : 'Female'; $l = implode(',', $_POST['lang']); $c = $_POST['coun']; $a = $_POST['addr']; if (isset($_FILES['pic'])) { $tmp = $_FILES['pic']['tmp_name']; if (is_uploaded_file($tmp)) { $oname = $_FILES['pic']['name']; $name = getRand() . '-' . $oname; $desc = "images/users/" . $name; @move_uploaded_file($tmp, $desc); } } $sql = "INSERT INTO user (Name,Email,Mobile,DOB,Pword,Gender,Language,Country,Address,Picture) VALUES ('{$n}','{$e}','{$m}','{$d}',md5('{$p}'),'{$g}','{$l}','{$c}','{$a}','{$name}')"; if (mysql_query($sql)) { header("location:showUsers.php"); exit; } else { echo "<b><u>Reason</u></b>: " . mysql_error(); } } else { header("location:regFORM.php"); } function getRand()
<?php $prize_arr = array( '0' => array('id'=>1,'prize'=>'平板电脑','v'=>3), '1' => array('id'=>2,'prize'=>'数码相机','v'=>5), '2' => array('id'=>3,'prize'=>'音箱设备','v'=>10), '3' => array('id'=>4,'prize'=>'4G优盘','v'=>12), '4' => array('id'=>5,'prize'=>'Q币10元','v'=>20), '5' => array('id'=>6,'prize'=>'下次没准就能中哦','v'=>50), ); foreach ($prize_arr as $key => $val) { $arr[$val['id']] = $val['v']; } $rid = getRand($arr); /*根据概率获取奖项id*/ $res['msg'] = ($rid==6)?0:1; $res['prize'] = $prize_arr[$rid-1]['prize']; /*中奖项*/ echo json_encode($res);exit; /*计算概率*/ function getRand($proArr) { $result = ''; /*概率数组的总概率精度*/ $proSum = array_sum($proArr); /*概率数组循环*/ foreach ($proArr as $key => $proCur) { /*相当于每次只能够抽取其中的一个奖项,没抽中就开始抽下一个奖项,直到最后*/ $randNum = mt_rand(1, $proSum); if ($randNum <= $proCur) {
#!/usr/bin/php <?php // timestamp, router, ip src, ip dst, proto, port src, port dst, bsize $routers = array("cisco", "juniper", "linux", "freebsd", "openbsd"); $ips = array("192.168.0.1", "192.168.0.2", "192.168.0.3", "192.168.0.4", "192.168.0.5", "192.168.0.6", "200.123.321.2", "200.123.321.1"); $protos = array("udp", "tcp", "icmp"); $apps = array("22", "80", "21", "8080", "443"); //http://kb.juniper.net/InfoCenter/index?page=content&id=KB14737 const MTU_SIZE = 1500; // 86400 == 1day/s 3600 == 1hr/s; 1488095 == max packets/s in 1GB const PACKETS_COUNT = 89285700; // 1488095×60 $i = 0; function getRand($mixed) { return $mixed[rand(0, count($mixed) - 1)]; } for ($i = 0; $i < PACKETS_COUNT; $i++) { echo time() + rand(0, 60) . "," . getRand($routers) . "," . getRand($ips) . "," . getRand($ips) . "," . getRand($protos) . "," . getRand($apps) . "," . getRand($apps) . "," . rand(0, MTU_SIZE) . "\n"; }
public function eggs() { if (!$this->customer->isLogged()) { $this->session->data['redirect'] = $this->url->link('account/newyear', '', 'SSL'); $this->redirect($this->url->link('account/login', '', 'SSL')); } $this->data['logged'] = $this->customer->isLogged(); $custormer_name = $this->customer->getFirstName(); //$this->data['text_logged'] = sprintf("您好,", HTTP_SERVER . 'order.html', $custormer_name, HTTP_SERVER . 'account-logout.html'); $this->data['text_logged'] = "您好,<a href='order.html' target='_blank'>" . $custormer_name . "</a>(<a href='account-logout.html'>退出</a>)"; $this->data['customer_id'] = $this->customer->getId(); $customer_id = $this->data['customer_id']; $this->load->model('account/customer'); $egg = $this->model_account_customer->getEggDate($customer_id); $egg_date = date("Y-m-d", strtotime($egg)); $time = date("Y-m-d", time()); $time1 = date("ymdHsi", time()); $this->data['egg_sign'] = $egg_date == $time ? 1 : 0; //var_dump(strtotime(date("2015-01-08 00:00:00"))); //var_dump(strtotime(date("2015-02-01 00:00:00"))); //敲打金蛋,2015-01-08时间戳为1420646400 if (!$this->data['egg_sign'] && isset($this->request->get['customer_id'])) { $prize_arr = array('0' => array('id' => 1, 'prize' => '100元现金券', 'v' => 1), '1' => array('id' => 2, 'prize' => '10元现金券', 'v' => 10), '2' => array('id' => 3, 'prize' => '5元现金券', 'v' => 30), '3' => array('id' => 4, 'prize' => '2元现金券', 'v' => 50), '4' => array('id' => 5, 'prize' => '1元现金券', 'v' => 55), '5' => array('id' => 6, 'prize' => '下次没准就能中哦', 'v' => 50)); foreach ($prize_arr as $key => $val) { $arr[$val['id']] = $val['v']; } $rid = getRand($arr); /*根据概率获取奖项id*/ switch ($rid) { case 1: $money = 100; break; case 2: $money = 10; break; case 3: $money = 5; break; case 4: $money = 2; break; case 5: $money = 1; break; default: $money = 0; break; } $data = array("sn" => $time1, "firstname" => $custormer_name, "getway" => 3, "endtime" => 1422720000, "addtime" => time(), "money" => $money, "sellmoney" => null, "state" => 1); $res['msg'] = $rid == 6 ? 0 : 1; if ($res['msg']) { $Getresult = $this->model_account_customer->editEggDate($customer_id); if ($Getresult) { $this->model_account_customer->addCoupon($data); } } else { $this->model_account_customer->editEggDate($customer_id); } $res['prize'] = $prize_arr[$rid - 1]['prize']; /*中奖项*/ echo json_encode($res); exit; } date_default_timezone_set("Asia/Shanghai"); $this->data['rewards'] = $this->model_account_customer->getCouponsGetway(); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/specialtpl/eggs.tpl')) { $this->template = $this->config->get('config_template') . '/template/specialtpl/eggs.tpl'; } else { $this->template = 'default/template/specialtpl/eggs.tpl'; } $this->response->setOutput($this->render()); }