473,856 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,$lottSha res);

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 3621
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,$lottSha res);

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*******@attgl obal.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,$lottSha res);

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.co mwrote:
>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,$lottSha res);

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.u k :: 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,$lottSha res);

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,$lottSha res);

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.co mwrote:
>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,$lottSha res);

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,$lottSha res);

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*******@attgl obal.net
=============== ===
Nov 11 '06 #8
In message <Wh************ ******@newsfe7-gui.ntli.net>
Kevin Williamson <ke************ ***@ntlworld.co mwrote:
>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();'|gr ep "PHP Version"
PHP Version =5.2.0
--
http://www.mladen-gogala.com

Nov 11 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
3718
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 appreciated.
6
10272
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 off. im getting a recurring error regarding the syntax of my main() function argument calling in lottery_numbers array. so any help as to whats glaringly going wrong here?? oh and some brief guidance on whats the easiest way to sort the numbers...
15
3344
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 layer. EG. bits-layer 1. Any way, I want the quiz to reorder the problems each time I take it. Here is part of the code i did so far for 62 components in the quiz.
7
1627
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
1659
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 numbers, none being the same. any help appreciated. thanks, Paul.
5
1306
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 Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim count As Integer Dim rndNumber(5) As Integer Dim userNumbers(5) As Integer
0
1256
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 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.
1
2229
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
4370
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
9766
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11066
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10800
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10391
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7934
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7098
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5962
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4177
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3203
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.