You are here: Re: random lottery draw funciton « PHP Programming Language « IT news, forums, messages
Re: random lottery draw funciton

Posted by Andy Hassall on 11/10/06 22:06

On Fri, 10 Nov 2006 21:15:01 GMT, Kevin Williamson
<kevin.williamson4@ntlworld.com> wrote:

>I've written a lottery programme in PHP that selects 10 winners a week
>from approximately 18,000 shares.
>
>The problem I have is that of the ten winners one week the same share
>number was drawn the next week and an adjacent share number the
>following week (that just happened to be owned by the same member)
>The program is now being looked at suspisciously.

How many times has the draw been done? Based on the information given there's
no firm evidence that anything's wrong - the people looking at it may be
falling for the Gambler's Fallacy.

>The main core of the random draw simply puts all the current share
>numbers into an array ($currWinner), draws a random number using the
>rand function between 1 and the number of shares ($lottshares) and
>returns the share id number.
>
>for the random element ofthe program I use:
>
>$currWinner = rand(1,$lottShares);
>
>is this random enough?

I believe rand() uses your operating system's default rand() system call, so
the quality of the pseudo-random numbers depends on your system. Generally this
is still "random enough", but that depends on your definition. If there's money
involved, then maybe not.

There's also mt_rand() which uses the Mersenne Twister algorithm, which has
some advantages over some other pseudo-random number generators. It's still
pseudo-random, but "real" randomness generally needs hardware based on some
random physical phenomenon (thermal noise, radioactive decay, etc.)

You should test your system by setting up a simple test harness that runs the
script some large number of times and saving the results. You can then analyse
the results to see if there are any obvious groupings, or whether the
distribution is roughly uniform.

>or is it possible that it needs seeding (although
>I don't totally understand seeding?

That depends on your PHP version - only older versions need to be explicitly
seeded.

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация