From: Brian Candler Date: 2009-10-21T18:14:12+09:00 Subject: Re: Randomly generated words from a set of letters > what would you do? If the result always has to be one of the pre-defined words, then the most efficient approach is to have all the words available and then just pick one from that set. If you don't mind reading this whole list into RAM, then it's easy: word = words[rand words.size] If it's huge and you want to keep it on disk, then I'd pre-format the dictionary as a CDB, where the key is a number in the range 0 to words.size-1. http://cr.yp.to/cdb.html http://raa.ruby-lang.org/project/cdb/ This allows any word to be found with at most two disk seeks. If you have a SQL database already available in your application, just use that. Again, I'd give each word a sequence number between 0 and N-1 to make it easy to pick one randomly. -- Posted via http://www.ruby-forum.com/.