1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Random Page in percentage [explanation needed]

Discussion in 'Black Hat SEO' started by LGZACRO, Sep 24, 2013.

Tags:
  1. LGZACRO

    LGZACRO Newbie

    Joined:
    Aug 31, 2013
    Messages:
    17
    Likes Received:
    0
    Hello everyone, I am looking how to make that 30 percent of my "pictures.html" visitors would be redirected to page1.html, and 70 percent to page2.html?
    I have found these:

    Code:
    <script type="text/javascript">
    (function(n){
     var pages = ['page1.htm', 'page2.htm', 'page3.htm'];
     n = n < 3? 0 : n < 8? 1 : 2;
     window.location.replace(pages[n]);
    })(Math.floor(Math.random() * 10));
    </script>
    but I am not sure I understand it right... can anyone explain this?
     
  2. Schvamp

    Schvamp Power Member

    Joined:
    Feb 13, 2012
    Messages:
    684
    Likes Received:
    549
    Location:
    Hogwarts
    Hey buddy. Sorry but I dont know javascript as I skipped that for some unknown reason.
    But if your site supports PHP I write a litle code for you.
    Code:
    <?php
    $random = rand(1, 100);
    if($random > 70){ //If dice hits over 70 (out of 100)do this
    echo '<meta http-equiv="refresh" content="0; ,URL=page1.html">'
    }else{ //Otherwise, do this
    echo '<meta http-equiv="refresh" content="0; ,URL=page2.html">'
    }
    ?>
    
    It should work, if it dosent, let me know as I wrote this just from the air.
     
    • Thanks Thanks x 1
    Last edited: Sep 24, 2013
  3. qrazy

    qrazy Senior Member

    Joined:
    Mar 19, 2012
    Messages:
    1,111
    Likes Received:
    1,712
    Location:
    Banana Republic
    This won't work because you haven't considered the weightage or frequency of the redirects.

    OP: Have a look at this example of banner rotator based on ratio/weight and with slight modification you can achieve what you want.


     
  4. Schvamp

    Schvamp Power Member

    Joined:
    Feb 13, 2012
    Messages:
    684
    Likes Received:
    549
    Location:
    Hogwarts
    Sorry for my english, could you please explain?
     
  5. qrazy

    qrazy Senior Member

    Joined:
    Mar 19, 2012
    Messages:
    1,111
    Likes Received:
    1,712
    Location:
    Banana Republic
    As OP said 30% of visitors would visit page-1 and 70% would visit page-2.

    But in your code, you just check for the value of the random number generated is above 70 and redirecting to page-2. It doesn't mean it will be redirected to page-2 70 out of 100 times. So there's no guarantee of any percentage redirects in this case.





     
    • Thanks Thanks x 1
    Last edited: Sep 24, 2013
  6. stugz

    stugz Junior Member

    Joined:
    Apr 14, 2013
    Messages:
    154
    Likes Received:
    33
    ^That is a far more complicated solution when there are only two choices and the choices are normalised. The idea posted in the PHP code is perfectly fine. Random numbers will be generated according to Gaussian distribution and so they are all equally likely to occur. Numbers over 70 will in the long run converge to being generated approximately 30% of the time. While it may not guarantee exactly 70% redirection to a one choice and 30% to the other - the code is perfectly fine for when there are only two choices. There is also no guarantee of percentages for the solution you linked. It too relies on random number generation and will also have the deviations from the weights in the same way as the other less complicated solution.
     
  7. Schvamp

    Schvamp Power Member

    Joined:
    Feb 13, 2012
    Messages:
    684
    Likes Received:
    549
    Location:
    Hogwarts
    Yes you're right. There is 70% change for EACH visitor to get redirected to page2.html and not 70% for all traffic in totall.
    I only took a look at the javascript in the OP and as I said, I'm no javascripter.
    But I got the feeling that the code I posted did the same thing, only diffrence was, it's PHP.

    I just tested the PHP code myself and had it load 1Mx10 times, out of 1 million this stats went to page2.html

    699839
    700245
    700437
    700188
    699829
    699859
    699695
    700392
    700166
    699835

    Out of 10M page loads 69,990923% was redirected to page2.
    Leaving 30,01% to page1.

    I think it's a fair number.
     
    Last edited: Sep 24, 2013
  8. lancis

    lancis Elite Member

    Joined:
    Jul 31, 2010
    Messages:
    1,632
    Likes Received:
    2,384
    Occupation:
    Entrepreneur
    Location:
    Milky Way
    Home Page:
    Its best to use "mt_rand" instead "rand". The numbers generated follow uniform distribution, not Gaussian - this is the reason its safe to assume that 30% will visit page 1 and 70% will visit page 2.