Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-11-2011, 06:37 PM   PM User | #1
hey2010
New to the CF scene

 
Join Date: Nov 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
hey2010 is an unknown quantity at this point
PHP National Lottery script

I'm trying to write a script which creates national lottery numbers.

I need to make the script do these things.

each line needs to be unique.
Able to ignore numbers.
need to able to select 100 line of lottery.
only 4 numbers can match previous lines.
I have been working on this for few days now but i can't get it to ignore numbers and get unique numbers on each line.

My biggest problem is that i need to make sure the numbers are not repeated. each line can have 4 or numbers as before line or after line.

PHP Code:
$max_number=50//select numbers between 1-50 
$ignor_numbers=array(3,5,6,9,21); //ignore these numbers
$maxn=6//max numbers per line
$max_line=5000// max number of lines
$max_lines=0// start point of line
$line =array();
$unique_numbers =4//each line needs have unique numbers

while ( $max_lines $max_line)
{
    
srand((double) microtime() * 1000000);
    while (
1>0) {
     
$lottery[] = rand(1$max_number);
     
$lottery array_unique($lottery);
     
     if( 
in_array($lottery$line ) ){     
     
     }
     
     if (
sizeof($lottery) == $maxn) {
        
sort($lottery);
        
$line[]=$lottery;
         break;
      }  
    }
    
    unset(
$lottery);
    
$max_lines++;
}

sort $line );

for( 
$i=0$i sizeof($line); $i++ ){
    
$each_line $line[$i];
    for( 
$j=0$j sizeof$each_line ); $j++ )
    {
        echo 
" ".$each_line[$j];
    }
    
    echo 
"<br>";
    

hey2010 is offline   Reply With Quote
Old 11-11-2011, 06:44 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
I don't know how picky you need to be about "random".
PHP doesn't really generate true random numbers.
Usually, it's not an issue ... but now you're talking about the lottery.

You can use a remote service like this to help make your script true random:
http://www.random.org/

Here is their API: http://www.random.org/clients/http/

I imagine there are other services like this. I just picked this because
I've used it before. If randomness quality is not an issue, then nevermind.


.
mlseim is offline   Reply With Quote
Reply

Bookmarks

Tags
lottery, national lottery, php, php script, script

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:56 PM.


Advertisement
Log in to turn off these ads.