The following depends heavily on the fact that certain operations, e.g.,  .. (range) and array indexing, are inherently integer operations. (BTW: The Windoze rand is not adequate for dealing with a large body of data like this; it's 15-bit IIRC!)

c:\@Work\Perl\monks>perl -wMstrict -le "chomp(my @words = <>); ;; for (1 .. 5 + rand 20) { my @line = map $words[ rand @words ], 0 .. rand 10; if ($#line) { $_ = ucfirst for $line[ 1 + rand $#line ] } print qq{\u@line.}; } " ..\..\moby\mwords\354984si.ngl Ouabaio soldiers loob Piedmontite phenylated nol. Zolle Torque ghbor. Oxygenicity Subpharyngal gastroscopic ventricular trainways incombinin +g indulgement avidin idiorepulsive. Understaff. Becrawls subclavicular Combustive. Wrestlers occluding cryptonema novelizations epexegesis legpulling def +icient publici phalangean Monkeyflower.

I think there's only one line that requires comment. TheloniusMonk's word corpus apparently includes capitalized and hyphenated words; mine doesn't. I'm not going to try to simulate hyphenated words, but I wanted, don't ask me why, to stick one capitalized word into each line to make my output look a little more like the OPed output. So the
    if ($#line) { $_ = ucfirst for $line[ 1 + rand $#line ] }
statement capitalizes a word other than the first in the line if the line has more than one word. (Update: The for statement modifier simply topicalizes the word randomly chosen from the array.) Whatever...

Update: I should have looked at Lotus1's Creating random sentences from a dictionary first. This post is essentially the same. Oh, well...


Give a man a fish:  <%-{-{-{-<


In reply to Re: First Run (updated) by AnomalousMonk
in thread First Run by TheloniusMonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.