The Random Hyperlink: How It's Done
The Header Code
It is convenient to initialize this array (or arrays, each corresponding to a different link on the page) in the header of the document, instead of taking up space within the <body> tag with messy code blocks. The code you need to insert is fairly straightforward, shown here in context within an HTML file:
Of course, "link" is a completely arbitrary name, although I personally recommend using similar names if you have a single array. Names like "link1", "link2", and so on work well if you are going to have multiple random links on a page. Simplicity is always best in computer code.
The Body Code
There are a few things to note about these code fragments. First, as mentioned above, as long as the basic formatting is preserved (semicolons, etc) you may condense it into one line. The actual code for the example link in this document is
For more information on how to economize your code, see this additional document.
More important than that, this code and the header code must be modified to allow choosing from a different number of links (currently choosing between three). The modification to the top part is easy: simply continue adding link[X]="foo.html"; lines, incrementing X by one each time. That change must be reflected in the random number generator, however. To modify that portion of code, you must type random_num = (math.round((Math.random()*X)+1));, where X is equal to one less than the number of elements in the array. For example, if you need the link to select one of ten arrays, replace X with 9. Do not forget that "random_num" is an arbitrary variable name, either.
In the end, the actual use of random links is up to you. It takes more effort to create a document that would be enhanced, rather than damaged, by random linking; however, the end result could well be creative and interesting in the hands of a talented writer. The tools have been laid out for you.