|
Posted by Kevin Williamson on 11/11/06 11:23
Thanks Andy,
In view of the advice received I'll use a seed and run a test with
several thousand draws just to make sure.
I appreciate the help
Kevin
Andy Hassall wrote:
> 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.
>
Navigation:
[Reply to this message]
|