I'm wanting to build a quick text generator for a project I'm working on. I've got a list of about 100 words (20 of which are represented here). I want to feed in a single number, how many paragraphs the user wants, and generate a completely random set of sentences, and words.

I've got an idea how I might code it in ColdFusion, but I wonder if it's possible to do it all in SQL. My table structure is at the bottom.

Here's my sample math:

-- paragraphs
par = 3
-- sentences per paragraph
spp = random(1,5)
-- words per sentence
wps = random(5, 20)

par * spp * wps = total words

The end result should be the specified number of paragraphs with random numbers of words per sentence and random number of sentences for each paragraph. While I was writing this out I realized that this might be more complicated than I was intending. I'll still go through with it as you SQL wizards might have aces up your sleeves.

Any ideas?

CREATE TABLE `words` (
`id` mediumint(8) unsigned zerofill NOT NULL auto_increment,
`word` varchar(30) NOT NULL,
`fkLibrary` smallint(5) unsigned zerofill NOT NULL,
PRIMARY KEY (`id`),
KEY `fkLibrary` (`fkLibrary`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=131 ;

INSERT INTO `words` VALUES (00000001, 'Elegant', 00001);
INSERT INTO `words` VALUES (00000002, 'grande', 00001);
INSERT INTO `words` VALUES (00000003, 'ladies', 00001);
INSERT INTO `words` VALUES (00000004, 'benefiting', 00001);
INSERT INTO `words` VALUES (00000005, 'sheer', 00001);
INSERT INTO `words` VALUES (00000006, 'pedigree', 00001);
INSERT INTO `words` VALUES (00000007, 'brilliant', 00001);
INSERT INTO `words` VALUES (00000008, 'butler', 00001);
INSERT INTO `words` VALUES (00000009, 'sport', 00001);
INSERT INTO `words` VALUES (00000010, 'Sterling', 00001);
INSERT INTO `words` VALUES (00000011, 'member', 00001);
INSERT INTO `words` VALUES (00000012, 'repertoire', 00001);
INSERT INTO `words` VALUES (00000013, 'symphony', 00001);
INSERT INTO `words` VALUES (00000014, 'caviar', 00001);
INSERT INTO `words` VALUES (00000015, 'luxury', 00001);
INSERT INTO `words` VALUES (00000016, 'Investments', 00001);
INSERT INTO `words` VALUES (00000017, 'treasure', 00001);
INSERT INTO `words` VALUES (00000018, 'impresario', 00001);