|
Posted by Jerry Stuckle on 11/11/06 15:31
Kevin Williamson wrote:
>>
>>> Hi,
>>>
>>> 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.
>>>
>>> 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? or is it possible that it needs seeding
>>> (although I don't totally understand seeding?
>>>
>>>
>>> Any help will be appreciated.
>>>
>>> thanks
>>> Kevin
>>
>>
>> Kevin,
>>
>> Yes, I admit that does look suspicious! Of course, it's always
>> possible for it to happen, but the when you're drawing 10 out of 18K
>> are much against it :-)
>>
>> Which version of PHP are you running? The reason I asked, versions
>> before 4.2 did not automatically seed the random number generator -
>> you need to do it. See srand().
>>
>> Version 4.2 and later do this automatically if the generator hasn't
>> been seeded.
>>
> Thanks Jerry,
>
> I'm not sure what version of PHP because I installed it on an intranet
> and unless I visit the company do not have access to check.
>
> I have had the guy send me the relevant file that contains the draw
> sequence to have a look at. I think I'll use srand as a matter of course
> and return the updated version...but I agree ... look suspect
>
> thanks again
>
> Kevin
>
> Jerry Stuckle wrote:
>
>> Kevin Williamson wrote:
(Top posting fixed)
Just a suggestion - you should always know what version of PHP is being
used. There are just too many differences, bug fixes, etc. to not. And
phpinfo() is your friend.
Knowing the version would have helped you get to the page in the docs
which would have told you to use srand() if you're below PHP 4.2. Or,
if you're at 4.2+, you need to look elsewhere.
Also, please don't top post.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|