SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select random number of paragraphs, sentences, and words from database

    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);
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Sentences are not composed of random words, they have structure. Composing that structure is probably something you should code in your target language rather than a query.

  3. #3
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand that Dan. The end goal of this is to have what amounts to gibberish text, something like this:

    "Elegant grande ladies benefiting grande sheer pedigree brilliant butler sheer sport. Sterling member, repertoire, symphony, caviar luxury. Investments treasure impresario cigar designer, blissfull noble art ladies elegant symbolizing."

    It means nothing, and is simply meant to be placeholder text, similar in function to the standard "Lorem Ipsum" text you might have seen before. It doesn't really matter what order the words are in, how many words per sentence, or sentences per paragraph. Well...I'll have parameters for those things, but you get the point.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •