Markov chain-based word salad generator
There are various methods to generate a random n-word text. Markov chain is one of them. 

Basic idea how to do this is described in Centennial of Markov Chains (by Oleksandr Pavlyk) under "Text Generation" - you generate n-grams carry info,  encode transitions and define a function to walk the graph (in a non-brute force manner).

Result will heavily depend on word corpus and their connections rather then algorithm implementation itself. 



The real problem is actually to generate the word corpus and connections from random text. In order to do this well you need to work out the grammatical structure of sentences. Because, you do not want to be doing this manually.

For example, consider the text:


  The strongest rain ever recorded in India shut down the financial hub
  of Mumbai, snapped communication lines, closed airports and forced
  thousands of people to sleep in their offices or walk home during the
  night, officials said today.


You want to tag word grammatical structure


  The/DT strongest/JJS rain/NN ever/RB recorded/VBN in/IN India/NNP
  shut/VBD down/RP the/DT financial/JJ hub/NN of/IN Mumbai/NNP ,/,
  snapped/VBD communication/NN lines/NNS ,/, closed/VBD airports/NNS
  and/CC forced/VBD thousands/NNS of/IN people/NNS to/TO sleep/VB in/IN
  their/PRP$ offices/NNS or/CC walk/VB home/NN during/IN the/DT night/NN
  ,/, officials/NNS said/VBD today/NN ./.


To do this you can use The Stanford Parser (ruby wrapper).