Jump to content

Recommended Posts

Hi,

 

I need to write some code for this but unsure where to start.

 

Basically i have a database of say 10 rows. I need to be able to input a number and some sort of fair algorithm will choose one of the rows.

 

The number will be from 6 to 10 numbers long, and will need to pick the same result each time based on that number.

 

Its for a lotto game

yeah thats pretty much it.

 

Each person buys a lottery ticket and a new row is created for them in a mysql database.

 

now to make the lottery fair, it needs to be based on a real lottery's random numbers.

 

My lottery will pick a random row, but it needs to be based on the lottery numbers, so that people can check that the row is correct and that i did not cheat.

 

 

Run it like a real lotto, where the jackpot stacks up until someone wins.  Then you could generate a random number to put into the row, or let them pick their own number.

If two numbers come up, they split the prize, or make the row unique, kicking it back if it fails.

 

If you MUST have a winner, draw until you find one.

 

Actually... Im not too sure if this is working correctly, could anyone check this for me.

 

 

<?php
$seed = "040935702352" ;
srand ($seed*12345);
$random_number = rand(1,100);
echo "$random_number";
?>  

 

$seed being the lottery number. It returns the same number for each seed which i think is fair. but for some reason sometimes if i change the number slightly (any number after an 8 or 9) then the result stays the same. i added in the *12345 to make it more random (i guess)

Are you sure you understand what seed is doing?

 

Random doesn't seem like something you're really looking for. You want a set output for a set input, and that's not random.

 

Want a winner every time? Screw the whole number system, just throw userid's in a table, and pick one at random. This can be proven, in code, that a random row has been chosen.

 

Want a number system with a guaranteed winner? You're going to have to assign numbers to players, not allow them to choose.

 

Want a system where players pick their numbers, and winning numbers are chosen randomly, and a winner is decided based on that? jcbones has the solution.

Using random you wont really be able to provide the same result everytime.

and if I understand correctly, your asking to randomly pick someone , but you have to be able to repeat picking the same person as proof? doesnt that kind of defeat the point of it being random? O_o

 

You have to prioritize which function is actually more important to the game itself.

 

To ensure you'll always have a winner you need the "random" to have the exact range as the number of rows ('players')

 

You want to use a seperate number entered ie winning lottery numbers aspect, well they purely base their sense from having multiple random numbers drawn from a 'hat'  but you want to enter this number? therefore taking away the 'lottery' aspect imo.

 

Why not broaden the controls of your 'game' and make it more like an actual game, get each contestant to pick say 5 numbers from 20 for example.

(if your looking at a low number of people entering for a higher odds at getting a winner you specify to your players pick 1 from each list in say a drop down list on a form with 5 lists each with the below range)

$randomnumber1 = rand(1,4)
$randomnumber2 = rand(5,
$randomnumber3 = rand(9,12)
$randomnumber4 = rand(13,16)
$randomnumber5 = rand(17,20)

winner = someone who gets 3/5 matchs for example. depending on what exactly your trying to achieve.

Somehow to me it reads like your trying to pretend its fair which if was the case it might look like..

 

players table would look like

| idticketnumber | winner | loser |  randomnumber   |
|            1           |      0     |       0 |                              |
|           2            |      0     |       0 |                             |
etc etc

$myrandomkey = $_GET['number'];

resultQuery = SELECT  `idticketnumber` `where randomnumber` == $myrandomnumber 

if ( resultquery = false ){
$winner = rand(1,10)
$query = "UPDATE set lotterytable `winner` = '1'  `randomnumber` = '$myrandomkey' where id=$winner";
} else 
echo idticketnumber 


 

 

you get the idea..

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.