<?php

 /*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/ /**
* Lottery class
*
* @author Rafal Strojek <strojek.rafal@gmail.com>
* @copyright 2014 (c) Rafal Strojek
* @version 0.1
*/ class Lottery
{
/**
* Default parameters
*/
private $params = array(); /**
* Numbers to drawn
*/
private $numbers = array(); /**
* Constructor
*
* @param array $params User-defined parameters
*/
public function __construct($params = array())
{
$this->params = array_merge($this->getDefaultParameters(),$params);
$this->numbers = range($this->params['from'], $this->params['to'], 1); $this->seedRand();
} /**
* Gets default parameters
*
* @return array Default Parameters
*/
public function getDefaultParameters()
{
return array(
'from' => 1,
'to' => 49,
'numbers' => 6,
'seed' => (int) ((float) microtime() * 1000000),
'pow' => pow(2,24),
);
} /**
* Gets parameters
*
* @return array Lottery parameters
*/
public function getParameters()
{
return $this->params;
} public function getSeed()
{
return (int) $this->params['seed'];
} private function setSeed($seed = null)
{
$this->params['seed'] = ($seed) ? $seed : $this->makeSeed(); // Return instance to shortcut
return $this;
} private function seedRand()
{
mt_srand($this->getSeed());
} private function makeSeed()
{
return (int) ((mt_rand() + ((float) microtime() * 1000000)) % $this->params['pow']);
} public function createTicket()
{
$ticket = array();
$array = $this->numbers; for($i = 0; $i < $this->params['numbers']; $i++)
{
$this->setSeed()->seedRand();
$key = mt_rand(0, (count($array) - 1)); $ticket[$i] = $array[$key];
array_splice($array, $key, 1);
} asort($ticket); return $ticket;
} public function createTickets($count = null)
{
if($count <= 0)
{
return array();
} $count = min(500, max(1, $count));
$tickets = array();
for($i = 0; $i < $count; $i++)
{
$tickets[$i] = $this->createTicket();
} return $tickets; }
}

最新文章

  1. 自定义RecyclerView.ItemDecoration,实现RecyclerView的分割线效果
  2. Sql 常用时间转换
  3. iScroll-5 API 中文版
  4. angularjs可交互的directive
  5. 项目新的需求,网页的自适应交付/响应式交付 Responsive/Adaptive Delivery
  6. Echarts 合并版本
  7. Entity Framework 无法对没有主键的视图映射实体的解决办法
  8. Linux下安装MySQL5.6
  9. &lt;!DOCTYPE html&gt;的问题
  10. Android开发之异步具体解释(二)之AsyncTask
  11. Android 组件化/模块化之路——在展示层搭建MVP结构
  12. HDU - 1847 巴什博弈
  13. 【Python】 发邮件用 smtplib &amp; email
  14. DateGridView控件与mysql交互
  15. Docker 镜像使用
  16. OneAPM大讲堂 | Java 异常日志记录最佳实践
  17. Win10+Ubuntu1604双系统
  18. scrapy框架之持久化操作
  19. Jetty学习四:部署到Jetty
  20. Get方法和post方法有何不同?

热门文章

  1. javascript 特性
  2. ReactNative学习-ListView
  3. hdu-5683 zxa and xor (位运算)
  4. 转: android app进程保活的文章列表
  5. MJ刷新控件MJRefreshFooterView上拉之后收不回来的解决办法
  6. UISearchDisplayController隐藏navigationBar需注意
  7. JQuery.Gantt(甘特图)开发
  8. Java之简单图形面积计算
  9. 如何用C#代码查找某个路径下是否包含某个文件
  10. JavaScript语言基础-环境搭建