Web Analytics Made Easy -
StatCounter Randomize - CodingForum

Announcement

Collapse
No announcement yet.

Randomize

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Randomize

    Hello,

    Alright, I've been trying to figure out how to do this, but nothing has come to mind.

    Say on a certain page, I get 5000 visitors a day.

    Out of those 5000 people, at random times throughout the day, I want to echo out a statement 12 times with a code that they can use.

    So 12 random visitors out of the 5000 would see it, at completely random times during a 24 hour period.

    How would I do this? Thanks!

  • #2
    you ment probability.

    might be very simple.

    random time = anytime on a range that you can defined using time function.

    your numbers (you can change them if you want more visitors to see it):
    1/5000^12 = a lot of zeros
    every visitor\hit gets 1/5000^12 chances to win.
    1/5000^12 is bigger than, mt_getrandmax, the max number you can get therefor i used that function.

    PHP Code:
    <?php
    $min 
    1;
    $max mt_getrandmax(); // a smaller number will get you more winnings probability's.
    $lucky_visitor mt_rand($min$max);
    if (
    $lucky_visitor == 1){
      echo 
    'statement.';
    }
    ?>
    you can use rand() as well but mt_rand() is better.
    :. -= | Eran | =- .:
    __________________

    Comment


    • #3
      Just something to keep in mind, if this is a contest of some sort you need to keep in mind that someone could repeatedly refresh the page and search for the new content.

      Comment


      • #4
        2 things:

        1. save the vistor ip + send him a cookie
        --> that way you now he had his try

        2. save the winners, that way you ensure your 12 people a day
        --> notice that if you don't pay attention to the first issue, it could be the same one.

        FuZion: there are some people that no matter what they don't have luck. even if it was 50:50 they might spent a hall day of refreshing the page without getting their lucky number (each refresh is the same probability like anybody else, except they lost x+1 times).
        :. -= | Eran | =- .:
        __________________

        Comment


        • #5
          2 things:

          1. save the vistor ip + send him a cookie
          --> that way you now he had his try

          2. save the winners, that way you ensure your 12 people a day
          --> notice that if you don't pay attention to the first issue, it could be the same one.

          FuZion: there are some people that no matter what they don't have luck. even if it was 50:50 they might spent a hall day of refreshing the page without getting their lucky number (each refresh is the same probability like anybody else, except they lost x+1 times).
          :. -= | Eran | =- .:
          __________________

          Comment


          • #6
            I thing you will not be able to do that script without help of cronjob You will need one very simple script which will executes every day at midnight and generate random 12 times... if you have no idea how to do that I could make a sample code. You will save that values in TXT file for example and when you will have user request you will check if the time written in TXT file is now or already passed you will show you code and remove that time from TXT file (the problem could be if 10 users will do request in the same second to prevent such situation you should lock file for reading so the parallel scripts will not be able to read it unless first one will finish its operation).

            Comment

            Working...
            X