joecooper Posted August 26, 2011 Share Posted August 26, 2011 Hi, I have created some code that picks a winning lottery ticket number based on the New York "Take 5" lottery. It uses the winning number (as an offically generated random number that i cannot cheat with) as a seed for the rand() function. This way it will always give the same result for that particular seed making it 100% transparent and that i cannot manipulate the results (without changing the code which will be published). The code is: <?php if (isset($_POST['submit'])){ $seed = $_POST['take5numbers']; $ticketssold = $_POST['tickets']; srand ($seed*13579); $random_number = rand(1,$ticketssold); echo "Winning ticket is $random_number"; }else{ ?> <form name="form1" method="post" action="result.php"> "Take 5" numbers from low to high (including leading 0's) <input type="text" name="take5numbers" id="end" size="20" /><br> Total tickets sold for round <input type="text" name="tickets" id="end" size="20" /><br> <input type="submit" name="submit" id="submit" value="Get Winning Ticket Number!"> </form> <? } ?> Can someone please tell me if the code is generating fair and unbias results? Quote Link to comment https://forums.phpfreaks.com/topic/245720-could-someone-verify-this-code/ Share on other sites More sharing options...
xyph Posted August 26, 2011 Share Posted August 26, 2011 This algorithm is very predictable assuming you don't cut off entering before the numbers are announced. Beyond that, it's a decent way to make a random number table that can be replicated. I understand what you were asking for in the last thread now. You're piggy-backing a well known random system to generate a verifiable lottery yourself. Keep in mind this though, for portability Niels Keurentjes 25-Feb-2011 01:22 Keep in mind that the Suhosin patch which is installed by default on many PHP-installs such as Debian and DirectAdmin completely disables the srand and mt_srand functions for encryption security reasons. To generate reproducible random numbers from a fixed seed on a Suhosin-hardened server you will need to include your own pseudorandom generator code. As a workaround To generate a random number which is different every day, I used the number of days after unix epoch as a seed: <?php srand(floor(time() / (60*60*24))); echo rand() % 100; ?> My provider upgraded the php server recently, and calling srand(seed) does not seem to set the seed anymore. To let srand set the seed, add the following line to your .htaccess file php_value suhosin.srand.ignore 0 Kudos to doc_z (http://www.webmasterworld.com/php/3777515.htm) Harmen Quote Link to comment https://forums.phpfreaks.com/topic/245720-could-someone-verify-this-code/#findComment-1262076 Share on other sites More sharing options...
joecooper Posted August 26, 2011 Author Share Posted August 26, 2011 my code shuts off the ticket buying 20 minutes before the results are drawn. Site is basic at the moment, and it uses somthing known as bit coins which is an online currency thats getting more popular. http://86.21.243.231/interbitlotto/ Quote Link to comment https://forums.phpfreaks.com/topic/245720-could-someone-verify-this-code/#findComment-1262079 Share on other sites More sharing options...
QuickOldCar Posted August 26, 2011 Share Posted August 26, 2011 I would read and make sure your site is legal. http://lotteriescouncil.org.uk/public/gamblingact/law.shtml Bitcoins or not, it still requires and uses trading of cash with gambling. Quote Link to comment https://forums.phpfreaks.com/topic/245720-could-someone-verify-this-code/#findComment-1262097 Share on other sites More sharing options...
joecooper Posted August 26, 2011 Author Share Posted August 26, 2011 actually its classed as virtual items. the site doesnt handle cash. Quote Link to comment https://forums.phpfreaks.com/topic/245720-could-someone-verify-this-code/#findComment-1262098 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.