Page 2 of 2 [ 18 posts ]  Go to page Previous  1, 2

StuartN
Veteran
Veteran

User avatar

Joined: 20 Jan 2010
Age: 61
Gender: Male
Posts: 1,569

06 Apr 2010, 4:19 pm

(Replace Google in the following with any suitable portal)

You could take a long list of words (like a spell-checker dictionary), select one word from the list using a random function and then feed that word to Google's "I'm Feeling Lucky" URL (assuming there is an equivalent of www.google.com/search?q=MyWord) and you should end up being redirected to Google's selection of the most appropriate page for that word.

Of course this is not random in the sense of uniformly distributed selection probability of valid URLs, but it returns something that could possibly be adapted to resemble the meaning of random you want. It also (I think) can limit porn exposure if you modify the SafeSearch preference in Google search settings.

As a starting point, this code displays one randomly-selected line from a file (motd.txt) in the style of Message Of The Day:

Quote:
motd=~/bin/motd.txt
length=$(wc -l $motd | cut -d " " -f 1)
let "line_number = $RANDOM % $length + 1"
line=$(head -$line_number $motd | tail -1)


If there is an "I'm Feeling Lucky" URL, then compose it using the $line variable containing the randomly selected word or phrase and use wget URL or something similar. For instance, "wget www.google.com/search?q=$line" would download the first page of search results.

EDIT: Apparently, according to http://www.seroundtable.com/archives/015944.html, if you add "&btnI=745" to the end of your web search, then it will do an "I'm Feeling Lucky", but in practice it works with some searches but not with others.



Moog
Veteran
Veteran

User avatar

Joined: 25 Feb 2010
Age: 46
Gender: Male
Posts: 17,671
Location: Untied Kingdom

11 Apr 2010, 7:36 am

Thanks Stuart! I found myself a random word generator and have been using that to fuel my searches.


_________________
Not currently a moderator