Thread: how to rotate url randomly?

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    5

    Post how to rotate url randomly?

    Hi All,

    Anybody knows how to create URL randomly?

    For example: I have 10 different websites. How do I link this 10 websites to a single URL and whenever someone visits this URL it will appear randomly?


    Thanks

  2. #2
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    Use javascript... create an array with the URLs of all the websites... then either grab the time and use the seconds as a random number generator or I believe there is a random number generator with JS. Or why not just have a drop-down box with all the sites in it?

    /edit - check here for something that may help you.
    Last edited by ober; 03-20-2003 at 07:44 AM.

  3. #3
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Well, don't look at the code, I did it in 3 minutes
    Code:
    <script language="JavaScript">
    function prRndUrl() {
    	var arr = new Array(10);
    	var rnd = Math.floor(Math.random()*10) //generate random
    
    	arr[0] = "http://www.cnn.com";
    	arr[1] = "http://www.bbc.com";
    	arr[2] = "http://www.cprogramming";
    	arr[3] = "http://www.oscar.com";
    	arr[4] = "http://www.java.sun.com";
    	arr[5] = "http://www.linux.org";
    	arr[6] = "http://www.mandrake.org";
    	arr[7] = "http://www.slackware.org";
    	arr[8] = "http://www.suse.org";
    	arr[9] = "http://www.microsoft.com";
    
    	document.write("Hello our random site today is: " + arr[rnd] + " enjoy");
    	window.open(arr[rnd],'Random','width=500,height=500');
    }
    </script>
    I don't know if it is this what you want... I tested it with the following code:
    Code:
    <html>
    <head>
    <title>Testing</title>
    <script language="JavaScript">
    function prRndUrl() {
    	var arr = new Array(10);
    	var rnd = Math.floor(Math.random()*10) //generate random
    
    	arr[0] = "http://www.cnn.com";
    	arr[1] = "http://www.bbc.com";
    	arr[2] = "http://www.cprogramming";
    	arr[3] = "http://www.oscar.com";
    	arr[4] = "http://www.java.sun.com";
    	arr[5] = "http://www.linux.org";
    	arr[6] = "http://www.mandrake.org";
    	arr[7] = "http://www.slackware.org";
    	arr[8] = "http://www.suse.org";
    	arr[9] = "http://www.microsoft.com";
    
    	document.write("Hello our random site today is: " + arr[rnd] + " enjoy");
    	window.open(arr[rnd],'Random','width=500,height=500');
    }
    </script>
    </head>
    
    <body onLoad="prRndUrl()">
    
    </body>
    </html>
    Last edited by Vber; 03-20-2003 at 08:54 AM.

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    5

    Thanks alot :)

    Hi,

    Yep, thats what I was looking for. Thanks alot guys!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. URL escape issue
    By George2 in forum C# Programming
    Replies: 2
    Last Post: 08-12-2008, 11:45 AM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  3. Randomly rearranging the elements in a vector
    By Signifier in forum C++ Programming
    Replies: 11
    Last Post: 08-01-2007, 12:21 PM
  4. Replies: 1
    Last Post: 07-02-2007, 09:22 AM
  5. Parse a URL
    By smithx in forum C Programming
    Replies: 12
    Last Post: 08-21-2006, 03:08 PM