N1CK3RS0N Posted October 19, 2009 Share Posted October 19, 2009 Heya fellas. I'm working on a currency system for forums and it is going to have a type of lottery system built into it. Trying to figure out the best way to make the drawings work. I'm still new to cron jobs but will have to figure out how to set them up to draw the numbers every hour. What I need to do is figure a way to make it draw 3 random numbers, which will be the ticket number. They need to be a number between 1-36 and cannot pick the same number twice. Any ideas to what would be the best way to go about doing this? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/178287-help-with-lottery-style-system/ Share on other sites More sharing options...
MadTechie Posted October 19, 2009 Share Posted October 19, 2009 I would probably do this $balls = range(1, 36); $rand_keys = array_rand($balls, 3); echo $balls[$rand_keys[0]] . "\n"; echo $balls[$rand_keys[1]] . "\n"; echo $balls[$rand_keys[2]] . "\n"; EDIT: of course this would need to be stored, in a file or database.. but i guessed the random side was the part you was stuck on! Quote Link to comment https://forums.phpfreaks.com/topic/178287-help-with-lottery-style-system/#findComment-940088 Share on other sites More sharing options...
thebadbad Posted October 19, 2009 Share Posted October 19, 2009 Or alternatively <?php $balls = range(1, 36); shuffle($balls); echo implode('<br />', array_slice($balls, 0, 3)); //or simply access the random numbers via $balls[0], $balls[1] and $balls[2] ?> Quote Link to comment https://forums.phpfreaks.com/topic/178287-help-with-lottery-style-system/#findComment-940093 Share on other sites More sharing options...
N1CK3RS0N Posted October 19, 2009 Author Share Posted October 19, 2009 I would probably do this $balls = range(1, 36); $rand_keys = array_rand($balls, 3); echo $balls[$rand_keys[0]] . "\n"; echo $balls[$rand_keys[1]] . "\n"; echo $balls[$rand_keys[2]] . "\n"; EDIT: of course this would need to be stored, in a file or database.. but i guessed the random side was the part you was stuck on! Cool. Will give that a shot. Thanks Yeah the random part is what I was stuck on. How it works is people will pick 3 diff numbers then buy the ticket. Then when the number is selected it will check to see if anyone tickets matches the numbers picked. If all 3 numbers match in order, its a jackpot and they take all the loot. If they match 3 numbers out of order they get like 10%, 2 numbers in order like 5%, 2 numbers out of order like 1%, Quote Link to comment https://forums.phpfreaks.com/topic/178287-help-with-lottery-style-system/#findComment-940096 Share on other sites More sharing options...
MadTechie Posted October 19, 2009 Share Posted October 19, 2009 here's an idea (added some debug) I am using shuffle to keep it simple, (I probably have logic error or typos) *untested* <?php //users numbers $myNums = array(10,15,5); $balls = range(1, 36); shuffle($balls); $win = array($balls[0],$balls[1],$balls[2]); //CHEATING - for debugging #$myNums = array($balls[0],$balls[1],$balls[2]); //3 balls in order #$myNums = array($balls[0],$balls[2],$balls[1]); //3 balls out order #$myNums = array($balls[1],$balls[0],$balls[2]); //2 balls out order #$myNums = array($balls[0],37,$balls[2]); //2 balls in order #$myNums = array(37,37,37); //no win $rate = 0; if($myNums[0] == $win[0]) $rate += 5; if($myNums[1] == $win[1]) $rate += 5; if($myNums[2] == $win[2]) $rate += 5; if(in_array($myNums[0],$win)) $rate += 1; if(in_array($myNums[1],$win)) $rate += 1; if(in_array($myNums[2],$win)) $rate += 1; if ($rate == 18 )echo "JackPot 100%"; if ($rate >= 15 )echo "JackPot 10%"; if ($rate >= 10 )echo "JackPot 5%"; if ($rate >= 3 ) echo "JackPot 1%"; ?> EDIT: edit noticed and fixed a dumb error Quote Link to comment https://forums.phpfreaks.com/topic/178287-help-with-lottery-style-system/#findComment-940107 Share on other sites More sharing options...
N1CK3RS0N Posted October 20, 2009 Author Share Posted October 20, 2009 here's an idea (added some debug) I am using shuffle to keep it simple, (I probably have logic error or typos) *untested* <?php //users numbers $myNums = array(10,15,5); $balls = range(1, 36); shuffle($balls); $win = array($balls[0],$balls[1],$balls[2]); //CHEATING - for debugging #$myNums = array($balls[0],$balls[1],$balls[2]); //3 balls in order #$myNums = array($balls[0],$balls[2],$balls[1]); //3 balls out order #$myNums = array($balls[1],$balls[0],$balls[2]); //2 balls out order #$myNums = array($balls[0],37,$balls[2]); //2 balls in order #$myNums = array(37,37,37); //no win $rate = 0; if($myNums[0] == $win[0]) $rate += 5; if($myNums[1] == $win[1]) $rate += 5; if($myNums[2] == $win[2]) $rate += 5; if(in_array($myNums[0],$win)) $rate += 1; if(in_array($myNums[1],$win)) $rate += 1; if(in_array($myNums[2],$win)) $rate += 1; if ($rate == 18 )echo "JackPot 100%"; if ($rate >= 15 )echo "JackPot 10%"; if ($rate >= 10 )echo "JackPot 5%"; if ($rate >= 3 ) echo "JackPot 1%"; ?> EDIT: edit noticed and fixed a dumb error Awesome thanks. Will have to test it out and do some work on that tomorrow. Any good resources for cron jobs? Quote Link to comment https://forums.phpfreaks.com/topic/178287-help-with-lottery-style-system/#findComment-940119 Share on other sites More sharing options...
Maq Posted October 20, 2009 Share Posted October 20, 2009 http://www.adminschoice.com/docs/crontab.htm I reference this site sometimes - http://www.adminschoice.com/docs/crontab.htm If you have cPanel, or some sort of interface your hosting provider gave you, then it should be relatively intuitive. Quote Link to comment https://forums.phpfreaks.com/topic/178287-help-with-lottery-style-system/#findComment-940122 Share on other sites More sharing options...
N1CK3RS0N Posted October 20, 2009 Author Share Posted October 20, 2009 http://www.adminschoice.com/docs/crontab.htm I reference this site sometimes - http://www.adminschoice.com/docs/crontab.htm If you have cPanel, or some sort of interface your hosting provider gave you, then it should be relatively intuitive. Actually, its going to be using vbulletin which has a built in cron job feature. I just have to tell it the PHP file to run and how often. I'll let you guys know tomorrow how it went. By the way, the drawings will be based every hour based on the servers times. Is there any way with PHP to have a count down to when the next drawing is? Or would that requires some kind of ajax? Quote Link to comment https://forums.phpfreaks.com/topic/178287-help-with-lottery-style-system/#findComment-940123 Share on other sites More sharing options...
MadTechie Posted October 20, 2009 Share Posted October 20, 2009 Is there any way with PHP to have a count down to when the next drawing is? Or would that requires some kind of ajax? Yeah that's more of a Javascript problem, you could have PHP echo some JS to set a JS variable and the have a timer to count down from it, to save having a full AJAX request Quote Link to comment https://forums.phpfreaks.com/topic/178287-help-with-lottery-style-system/#findComment-940125 Share on other sites More sharing options...
Gayner Posted October 20, 2009 Share Posted October 20, 2009 here's an idea (added some debug) I am using shuffle to keep it simple, (I probably have logic error or typos) *untested* <?php //users numbers $myNums = array(10,15,5); $balls = range(1, 36); shuffle($balls); $win = array($balls[0],$balls[1],$balls[2]); //CHEATING - for debugging #$myNums = array($balls[0],$balls[1],$balls[2]); //3 balls in order #$myNums = array($balls[0],$balls[2],$balls[1]); //3 balls out order #$myNums = array($balls[1],$balls[0],$balls[2]); //2 balls out order #$myNums = array($balls[0],37,$balls[2]); //2 balls in order #$myNums = array(37,37,37); //no win $rate = 0; if($myNums[0] == $win[0]) $rate += 5; if($myNums[1] == $win[1]) $rate += 5; if($myNums[2] == $win[2]) $rate += 5; if(in_array($myNums[0],$win)) $rate += 1; if(in_array($myNums[1],$win)) $rate += 1; if(in_array($myNums[2],$win)) $rate += 1; if ($rate == 18 )echo "JackPot 100%"; if ($rate >= 15 )echo "JackPot 10%"; if ($rate >= 10 )echo "JackPot 5%"; if ($rate >= 3 ) echo "JackPot 1%"; ?> EDIT: edit noticed and fixed a dumb error Awesome thanks. Will have to test it out and do some work on that tomorrow. Any good resources for cron jobs? Why in the world does this have to do with cron jobs? Quote Link to comment https://forums.phpfreaks.com/topic/178287-help-with-lottery-style-system/#findComment-940165 Share on other sites More sharing options...
Stephen Posted October 20, 2009 Share Posted October 20, 2009 Why in the world does this have to do with cron jobs? You mean besides him mentioning how he is "...still new to cron jobs but will have to figure out how to set them up to draw the numbers every hour" in his original post? I have no clue. Quote Link to comment https://forums.phpfreaks.com/topic/178287-help-with-lottery-style-system/#findComment-940166 Share on other sites More sharing options...
Gayner Posted October 20, 2009 Share Posted October 20, 2009 Why in the world does this have to do with cron jobs? You mean besides him mentioning how he is "...still new to cron jobs but will have to figure out how to set them up to draw the numbers every hour" in his original post? I have no clue. Why would somone use cron jobs on lottery script if user input's to win.. lol Or set time in php to draw it every x minutes.... Quote Link to comment https://forums.phpfreaks.com/topic/178287-help-with-lottery-style-system/#findComment-940178 Share on other sites More sharing options...
N1CK3RS0N Posted October 20, 2009 Author Share Posted October 20, 2009 here's an idea (added some debug) I am using shuffle to keep it simple, (I probably have logic error or typos) *untested* <?php //users numbers $myNums = array(10,15,5); $balls = range(1, 36); shuffle($balls); $win = array($balls[0],$balls[1],$balls[2]); //CHEATING - for debugging #$myNums = array($balls[0],$balls[1],$balls[2]); //3 balls in order #$myNums = array($balls[0],$balls[2],$balls[1]); //3 balls out order #$myNums = array($balls[1],$balls[0],$balls[2]); //2 balls out order #$myNums = array($balls[0],37,$balls[2]); //2 balls in order #$myNums = array(37,37,37); //no win $rate = 0; if($myNums[0] == $win[0]) $rate += 5; if($myNums[1] == $win[1]) $rate += 5; if($myNums[2] == $win[2]) $rate += 5; if(in_array($myNums[0],$win)) $rate += 1; if(in_array($myNums[1],$win)) $rate += 1; if(in_array($myNums[2],$win)) $rate += 1; if ($rate == 18 )echo "JackPot 100%"; if ($rate >= 15 )echo "JackPot 10%"; if ($rate >= 10 )echo "JackPot 5%"; if ($rate >= 3 ) echo "JackPot 1%"; ?> EDIT: edit noticed and fixed a dumb error Awesome thanks. Will have to test it out and do some work on that tomorrow. Any good resources for cron jobs? Why in the world does this have to do with cron jobs? Need it to draw the numbers hourly. Something has to tell the script to run and when. Quote Link to comment https://forums.phpfreaks.com/topic/178287-help-with-lottery-style-system/#findComment-940684 Share on other sites More sharing options...
mikesta707 Posted October 20, 2009 Share Posted October 20, 2009 Why in the world does this have to do with cron jobs? You mean besides him mentioning how he is "...still new to cron jobs but will have to figure out how to set them up to draw the numbers every hour" in his original post? I have no clue. Why would somone use cron jobs on lottery script if user input's to win.. lol Or set time in php to draw it every x minutes.... umm... in real life lotteries work on a "cron-job" like system. The winning numbers are drawn every x amount of time. the fact that the post had the word lottery system should have given it away... not to mention thats what OP asked for Quote Link to comment https://forums.phpfreaks.com/topic/178287-help-with-lottery-style-system/#findComment-940687 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.