Jump to content

Recommended Posts

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!  ;D

Link to comment
https://forums.phpfreaks.com/topic/178287-help-with-lottery-style-system/
Share on other sites

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!

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%,

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

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?

 

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.

 

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. :D

 

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?

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

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?

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....

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.