Get Random Results (on Purpose)

Surfing random pages can turn up some brilliant finds.

Why would any researcher worth her salt be interested in random pages? While surfing random pages isn’t what one might call a focused search, you’d be surprised at some of the brilliant finds that you’d never have come across otherwise. I’ve loved random page generators associated with search engines ever since discovering Random Yahoo! Link (, although no longer working at the time of this writing). It made me think that creating such a thing to work with the Google API might prove interesting, useful even.

The Code

This code searches for a random number between 0 and 99999 (yes, you can search for 0 with Google) in addition to a modifier pulled from the @modifiers array. To generate the random page, you don’t, strictly speaking, need something from the modifer array. However, it helps make the page selection even more random.

With the combination of a number between 0 and 99999 and a modifier from the @modifiers array, Google will get a list of search results, and from that list you’ll get a “random” page. You could go higher with the numbers if you wanted, but I wasn’t sure that this hack would consistently find numbers higher than 99999. (Zip Codes are five digits, so I knew a five-digit search would find results more often than not.)

Save the code as a CGI script named goorandom.cgi. The only change you need to make is to replace insert key here with your Google ...

Get Google Hacks, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.