random lottery draw funciton

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin Williamson

    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
  • Jerry Stuckle

    #2
    Re: random lottery draw funciton

    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.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Moot

      #3
      Re: random lottery draw funciton


      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.

      Comment

      • Andy Hassall

        #4
        Re: random lottery draw funciton

        On Fri, 10 Nov 2006 21:15:01 GMT, Kevin Williamson
        <kevin.williams on4@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 :: andy@andyh.co.u k :: http://www.andyh.co.uk
        http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

        Comment

        • Kevin Williamson

          #5
          Re: random lottery draw funciton

          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.
          >

          Comment

          • Kevin Williamson

            #6
            Re: random lottery draw funciton

            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.
            >

            Comment

            • Kevin Williamson

              #7
              Re: random lottery draw funciton

              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.williams on4@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.
              >

              Comment

              • Jerry Stuckle

                #8
                Re: random lottery draw funciton

                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.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • Kevin Wells

                  #9
                  Re: random lottery draw funciton

                  In message <Whi5h.13382$GX 2.5884@newsfe7-gui.ntli.net>
                  Kevin Williamson <kevin.williams on4@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

                  ICQ 238580561
                  Nor shall my sword sleep in my hand.

                  Comment

                  • Mladen Gogala

                    #10
                    Re: random lottery draw funciton

                    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


                    --


                    Comment

                    • Kevin Williamson

                      #11
                      Re: random lottery draw funciton

                      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 <Whi5h.13382$GX 2.5884@newsfe7-gui.ntli.net>
                      Kevin Williamson <kevin.williams on4@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.
                      >

                      Comment

                      • Kevin Williamson

                        #12
                        Re: random lottery draw funciton

                        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();'|gr ep "PHP Version"
                        PHP Version =5.2.0
                        >
                        >

                        Comment

                        Working...