Tutorial :“Random Article” Feature on wikipedia.com [closed]


i would like to know what algorithm and what programming language wikipedia is using to randomly choose an article to display.

i would also like to know how does it work so fast?


Here's information on that.

Every article is assigned a random number between 0 and 1 when it is created (these are indexed in SQL, which is what makes selection fast). When you click random article it generates a target random number and then returns the article whose recorded random number is closest to this target.

If you are interested you can read the actual code here.


Something along this lines:

 "SELECT cur_id,cur_title          FROM cur USE INDEX (cur_random)          WHERE cur_namespace=0 AND cur_is_redirect=0          AND cur_random>RAND()          ORDER BY cur_random          LIMIT 1"  


From MediaWiki.org:

MediaWiki is a free software wiki package written in PHP, originally for use on Wikipedia. It is now used by several other projects of the non-profit Wikimedia Foundation and by many other wikis, including this website, the home of MediaWiki.

MediaWiki is open source, so you can download the code and inspect it, to see how they have implemented this feature.


If you look at the source, they use PHP/MySQL a sort and filter pages by pregenerated random values (page_random column) that have an index on them.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »