Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
url = 'http://en.wikipedia.org/w/api.php?action=query&format=json&prop=links&callback=onCallback&titles='
url2 = 'http://en.wikipedia.org/wiki/'
function randItem (array) {
    return array[Math.floor(Math.random() * array.length)]
    };
function load_links (title) {
    script = document.createElement("script");
    script.setAttribute('src',url + title);
    script.setAttribute('lang','javascript');
    document.body.appendChild(script);
    };
function onCallback (data) {
    k = data['query']['pages'];
    for (x in k) {
        links = k[x]['links'];
        };
    the_link = randItem(links);
    document.location = url2 + the_link['title'];
    };
$(function(){
    addPortletLink ('p-cactions','javascript:load_links(wgPageName)','RL','pt-rl','Random link','',false);
    });