3

Sometimes I feel like I want to use some sort of URL which redirects to a random site on the Stack Exchange network for the purpose of discovering new, interesting and useful Stack Exchange network sites.

random.stackexchange.com does not exist

  • 2
    It should be easy enough to create that... alternatively, just pick something from the Hot Network Questions. – S.L. Barth - Reinstate Monica Apr 2 '14 at 9:32
  • Code highlight on Meta is pretty minor, no need to edit just to add it. Thanks for the efforts though! – Shadow Wizard is Ear For You Apr 2 '14 at 11:17
  • @ShadowWizard sorry I just love when everything works 100% correctly. though I will learn my lesson now, thank you for your effort too, sheriff -) – Bruno Gelb Apr 2 '14 at 11:20
  • Actually I approved your latest edit, two others deemed it too minor. – Shadow Wizard is Ear For You Apr 2 '14 at 11:23
  • @ShadowWizard ye, I've already read the history of that edit. -) – Bruno Gelb Apr 2 '14 at 11:25
5

Taking Sklivvz's advice I built a jsfiddle that will redirect you automagically to a random site.

Since the API call is "heavy" and limited, please don't run the below code too many times.

Let's cut to the slack!

The Random Stack Exchange™ Site Jumper Turbo is here:

var jumperDiv = $('#Jumper');
jumperDiv.html('Loading, please wait...');
$.getJSON("https://api.stackexchange.com/2.2/sites?page=1&pagesize=999&?jsonp=wrapperFunc", function(data) {
    $('#RemainingQuota').html('Quota remaining: ' + data.quota_remaining + '<hr />');
    var allSites = [];
    for (var i = 0; i < data.items.length; i++) {
        //don't take meta sites
        if (data.items[i]["site_state"] != "linked_meta")
            allSites.push(data.items[i]["site_url"]);
      }
    Jump(allSites);
});
    
function Jump(allSites) {
    var randSiteUrl = allSites[parseInt(Math.random() * allSites.length)];
    jumperDiv.html('<a href="' + randSiteUrl + '">Jump to</a> ' + randSiteUrl + '!');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="RemainingQuota"></div>
<div id="Jumper"></div>

|improve this answer|||||
  • wow! :) how to read the code of this jsfiddle? It auto-runs every time I click the link – Bruno Gelb Apr 2 '14 at 11:00
  • @aspect_mkn8rd see my edit. :) – Shadow Wizard is Ear For You Apr 2 '14 at 11:06
  • JSFiddle broken here. Luckily there is still the code. – Patrick Hofman Nov 7 '16 at 15:06
  • @Pat yeah, weird. Maybe like imgur, they remove inactive fiddles. Using stack snippet instead now. – Shadow Wizard is Ear For You Nov 7 '16 at 15:12
  • 1
    @TheBitByte good point, done. :) – Shadow Wizard is Ear For You Nov 7 '16 at 15:19
  • @ShadowWizard It jumps sometimes to meta sites. – Buffer Over Read Nov 7 '16 at 15:34
  • 1
    @TheBitByte yeah, I don't filter the list... but I should. Thanks! – Shadow Wizard is Ear For You Nov 7 '16 at 15:35
  • What about grabbing all the sitenames until the quota is finished, filtering meta sites out, and having a "random site" button that grabs sites from that internal list and displays them? – Buffer Over Read Nov 7 '16 at 15:37
  • Or, a crazier solution, manually grab the names from the HTML of stackexchange.com/sites. Not sure how reliable that solution would be if the page changes or new sites are added to it, though. – Buffer Over Read Nov 7 '16 at 15:40
  • @TheBitByte can't do those, it's client side and can't read remote pages, only the API which provides JSONP. – Shadow Wizard is Ear For You Nov 7 '16 at 15:42
  • @TheBitByte that's what I was referring to, can't read the HTML of stackexchange.com/sites – Shadow Wizard is Ear For You Nov 7 '16 at 15:44
  • You mean stack snippets can't access remote pages? I guess maybe they're sandboxed or something. – Buffer Over Read Nov 7 '16 at 15:45
  • 1
    @TheBitByte any client side JavaScript code is restricted to read contents only of the same domain as the server where it sits, yes. Stack Snippets, jsfiddle, all of them. :) – Shadow Wizard is Ear For You Nov 7 '16 at 15:46
3

You can get the list of sites here as JSON:

http://api.stackexchange.com/docs/sites#filter=default&run=true

(call without help page: http://api.stackexchange.com/2.2/sites)

From that, it should be a Javascript one liner...

$.get("http://api.stackexchange.com/2.2/sites?pagesize=1000", function(data) {
  console.log(data.items[Math.floor(Math.random()*data.items.length)]["site_url"]);
});
|improve this answer|||||
1

Well there is no such URL as of now, but the closest you can get to it is the All Sites url. You can randomly select a StackExchange site.

* To make it really very random, you can click on a random space in that page by closing your eyes ;)

|improve this answer|||||
  • perhaps I will write some js code for getting random url from this page. Thx! – Bruno Gelb Apr 2 '14 at 9:37
  • @aspect_mkn8rd - Well yeah, that could work too :) – SudoRahul Apr 2 '14 at 9:38
  • btw sir what's that letters in your nickname? Auto completion (after at sign) doesn’t seems to work on you, weird o_0 – Bruno Gelb Apr 2 '14 at 9:40
  • @aspect_mkn8rd - Since this is my post, you need not refer me using the @ symbol. SE has handled that. And regarding the special characters, well those are some unicode characters I picked up from the internet and on any other post which is not mine, but I've commented, you can very well use the @ symbol to address me. It works :) – SudoRahul Apr 2 '14 at 9:42
  • 1
    @aspect_mkn8rd now you can use @, when you will press it the weird name will auto appear as its first character is special. – Shadow Wizard is Ear For You Apr 2 '14 at 11:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .