473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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 3563
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Paul Rubin | last post by:
http://www.nightsong.com/phr/python/sharandom.c This is intended to be less predicable/have fewer correlations than the default Mersenne Twister or Wichmann-Hill generators. Comments are...
6
by: moi | last post by:
hi, i have an assignment to put 6 pseudo random numbers into an array to simulate drawing 6 lottery numbers between 1-49. the code i have to do this so far is listed below. i dont think its far...
15
by: alanbe | last post by:
Greetings I am making a flashcard type application to help me in my TCP/IP protocols test. My instructor will test us periodically on how a device or networking function relates to the OSI...
7
by: BOOGIEMAN | last post by:
//Why this doesn't work : using System; using System.Threading; class RandomObjectDemo { public static void Main( ) { Thread.Sleep( 1 );
5
by: Milsnips | last post by:
hi there, i'm after a small function that is kindof like the lottery picker programs, i pass it some numbers, say (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) and i want it to return me 3 random...
5
by: Anthony | last post by:
For Some reason, i get the same value everytime... Ive tested the RND Function with msgboxes and labels, they all have no influence on the RND Function... It still doesnt work... Private Sub...
0
by: NTL Newsgroups | last post by:
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...
1
by: um33 | last post by:
Hello guys, I am knew to the VB6 and I do need to wrie a program that generate 6 lottery numbers in ascending Order and Non repeating as well. Thanks
8
by: Miktor | last post by:
I'm trying to write a lottery number generator for the uk national lottery. Any clues where I'm going wrong? #include <cstdlib> #include <iostream> using namespace std; int main ()
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.