Getting 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 you’d never have come across otherwise. I’ve loved random page generators associated with search engines ever since discovering Random Yahoo! Link ( and thought creating such a thing to work with the Google API might prove interesting, useful even.

The Code

What this code does is search 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.)

The Code

#!/usr/local/bin/perl # goorandom.cgi # Creates a random Google query and redirects the browser to # the top/first result. # goorandom.cgi is called as a CGI without any form input ...

Get Google Hacks now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.