JavaScript that favors certain URLs!

Discussion in 'Web Design and Development' started by Aperture, Nov 7, 2006.

  1. Aperture macrumors 68000

    Aperture

    Joined:
    Mar 19, 2006
    Location:
    PA
    #1
    Hi, I implemented a JavaScript code onto a .php file and made it my index on KevinSchaefer.net. The code is setup to redirect to a set of 3 URLs randomly, although it seems to favor one. I did 10 reloads, (Yes, going back to the index.php file ;) ) and 6/10 times it directed to this.. Sometimes it favors this. Sorry if this sounds insane, its kind of annoying. Is there a way to make it purely random? Here is the code im using:

    Code:
    	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    	<script type="text/javascript">
          var pageArr = ["/home/1/index.html", "/home/2/index.html", "/home/3/index.html"];
    		document.location.href = pageArr[Math.ceil(Math.random()*pageArr.length)-1];
    	</script>
    Any help appreciated.

    Thanks, Kevin
     
  2. mnkeybsness macrumors 68030

    mnkeybsness

    Joined:
    Jun 25, 2001
    Location:
    Moneyapolis, Minnesota
    #2
    You're only generating a random value of a set of three... the less items, the more chance you will have to continually land on the same generated number. Didn't you ever take statistics?
     
  3. ThunderLounge macrumors 6502

    ThunderLounge

    Joined:
    Sep 20, 2006
    #3
    Um, if it's in a php file, why not use php instead of javascript?
     

Share This Page