Code: Select all
<?php
class lottery
{
function lottery()
{
static $seed = true;
if($seed)
{
srand((double)microtime()*1000000 );
$seed = false;
}
for($i = 1; $i < 50; $i++)
{
$this->numbers[] = $i;
}
}
function gen_numbers($pulls)
{
for($i = 0; $i < $pulls; $i++)
{
$this->pulls[] = $this->pull();
}
}
function pull()
{
shuffle($this->numbers);
$pull = array_slice($this->numbers, 0, 6);
sort($pull);
return $pull;
}
function get_weeks()
{
$this->weeks = 1;
while(($this->pull = $this->pull()) and (!in_array($this->pull, $this->pulls)))
{
$this->weeks++;
}
return $this->weeks;
}
function result()
{
$output = 'After '.($c = count($this->pulls)).' attempt'.(($c == 1)?null:'s').' per week your numbers ('.implode(', ', $this->pull).') came up on ';
$ts = (($this->weeks % 52.1785)*7*24*60*60) + time();
$output .= date('F jS ', $ts) . floor(date('Y', $ts) + ($this->weeks / 52.1785));
return $output;
}
}
$bad_news = new lottery;
$bad_news->gen_numbers(1);
echo $bad_news->get_weeks().' weeks<br>';
echo $bad_news->result();
?>
