468,507 Members | 1,531 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,507 developers. It's quick & easy.

random lottery draw funciton

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
Nov 10 '06 #1
11 3253
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.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 10 '06 #2

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

While (all things being random) it isn't technically impossible, it is
suspicious. Aside from the PHP version seeding issue Jerry mentioned,
you may want to just run a big simulation, running a few thousand
"drawings", then get the number of occurances of each share.

If it looks like a few numbers start jumping out more often than
others, you may have a problem. Ideally, in a truely random system,
when run for a sufficiently large set, all shares should have
relatively the same number of occurances.

Nov 10 '06 #3
On Fri, 10 Nov 2006 21:15:01 GMT, Kevin Williamson
<ke***************@ntlworld.comwrote:
>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 :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Nov 10 '06 #4
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:
>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.
Nov 11 '06 #5
Thanks Moot,

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

Moot wrote:
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


While (all things being random) it isn't technically impossible, it is
suspicious. Aside from the PHP version seeding issue Jerry mentioned,
you may want to just run a big simulation, running a few thousand
"drawings", then get the number of occurances of each share.

If it looks like a few numbers start jumping out more often than
others, you may have a problem. Ideally, in a truely random system,
when run for a sufficiently large set, all shares should have
relatively the same number of occurances.
Nov 11 '06 #6
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
<ke***************@ntlworld.comwrote:
>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.
Nov 11 '06 #7
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.
js*******@attglobal.net
==================
Nov 11 '06 #8
In message <Wh******************@newsfe7-gui.ntli.net>
Kevin Williamson <ke***************@ntlworld.comwrote:
>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
[snip]
Just create a php file with the following commands

<?php

phpinfo();

?>

That will tell you what version of php you are running amongst other
things.

--
Kev Wells http://kevsoft.topcities.com
http://kevsoft.co.uk/
ICQ 238580561
Nor shall my sword sleep in my hand.
Nov 11 '06 #9
On Sat, 11 Nov 2006 11:16:06 +0000, Kevin Williamson wrote:
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.
$ php -r 'phpinfo();'|grep "PHP Version"
PHP Version =5.2.0
--
http://www.mladen-gogala.com

Nov 11 '06 #10
thanks Kevin, I know about phpinfo(). its just that I haven't got access
to their server to run it.

I've now used mt_srand() and mt_rand for my test bed and will run a
check using these.
thanks

Kevin

Kevin Wells wrote:
In message <Wh******************@newsfe7-gui.ntli.net>
Kevin Williamson <ke***************@ntlworld.comwrote:
>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

[snip]
Just create a php file with the following commands

<?php

phpinfo();

?>

That will tell you what version of php you are running amongst other
things.
Nov 12 '06 #11
thanks Mladen, I know about phpinfo(). its just that I haven't got
access to their server to run it.

I've now used mt_srand() and mt_rand for my test bed and will run a
check using these.
thanks

Kevin

Mladen Gogala wrote:
On Sat, 11 Nov 2006 11:16:06 +0000, Kevin Williamson wrote:
>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.

$ php -r 'phpinfo();'|grep "PHP Version"
PHP Version =5.2.0

Nov 12 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by Paul Rubin | last post: by
6 posts views Thread by moi | last post: by
7 posts views Thread by BOOGIEMAN | last post: by
5 posts views Thread by Milsnips | last post: by
5 posts views Thread by Anthony | last post: by
reply views Thread by NTL Newsgroups | last post: by
8 posts views Thread by Miktor | last post: by
3 posts views Thread by gieforce | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.