Ode to a random number
Moron
created: 2006-06-19 08:55:56
#!/usr/bin/perl

open my $dict, ";
my $count = 100*rand();
{ use integer; $count /= 1; }
for ( 0..$count ) {
    my $ptr = rand() * $#words;
    chomp $words[$ptr];
    unless( $_ ) {
        $words[ $ptr ] =~ /^(.)(.*)$/;
        my $b = uc( $1 );
        $words[$ptr ] = $b . $2;
    }
    if ( $_ < $count ) {
        print $words[$ptr] . ' ';
    }
    else {
        print $words[$ptr] . ".\n";
    }
}

-M

Free your mind

Re: Ode to a random number
created: 2006-06-19 10:09:45

"dying Asilomar straggle suggestively overtakes relive" – cool.

Anyway, random generated ode? I have one of those too: Re: Ode for getprotobyname.

Re: Ode to a random number
created: 2006-06-20 09:18:31
My 'puter's bigger than your 'puter... and it's /usr/share/dict/words... :D

ps ... but I like it++:

Stercorianism pyroantimonic slandering imperspicuity midmain.

Don Wilde
"There's more than one level to any answer."
Re^2: Ode to a random number
created: 2006-06-20 09:28:52
lol - ok I'll reduce the built-in prejudice -- but only a little! ;)

-M

Free your mind

Re^3: Ode to a random number
created: 2006-06-20 12:12:07
Good idea! Might make Wallace trip over 'is own feet too much, unless Gromit built a Perl robot speaker... hmmm... Gromit knowing Perl... 'nother good idea. Memo to self! :D

Don Wilde
"There's more than one level to any answer."
Re: Ode to a random number
created: 2006-06-20 12:53:41
This modified version avoids proper nouns and applies some meter to the verses by counting (half-)syllables.
#!/usr/bin/perl
#ode to a random number v0.2
open my $dict, ";
my $count = 70*rand();
{ use integer; $count /= 1; }
my $syllables = 0;

for ( 'a', 'e', 'i', 'o', 'u' ) {
    $vowel{ $_ } = 1;
}

for ( 0..$count ) {
    my $ptr;
    my $thissyll;
    do {
        $ptr = rand() * $#words;
        $thissyll = Syllables( $words[$ptr] );
    } until ( $words[$ptr] eq lc( $words[$ptr] )
              and ((20-$syllables-$thissyll) >= 0 ));
    $syllables += $thissyll;

    chomp $words[$ptr];
    unless( $_ ) {
        $words[ $ptr ] =~ /^(.)(.*)$/;
        my $b = uc( $1 );
        $words[$ptr ] = $b . $2;
    }
    if ( $_ < $count ) {
        print $words[$ptr];
        if ( $syllables >= 20 ) {
            print ";\n";
            $syllables = 0;
        }
        else { print ' '; }
    }
    else {
        print $words[$ptr] . ".\n";
    }
}

sub Syllables {
    my $word = shift;
    chomp $word;
    my $lv = 0;
    my $tv;
    my $syll = 0;
    for my $letter( split '', $word ) {
        $tv = $vowel{ $letter };
        ( $tv == $lv ) or $syll++;
        $lv = $tv;
    }
    return $syll;
}
First output:
Policeman nereid spokesman trendy;
fragmentary magnetite enunciate;
dyspeptic lean recombinant decile myrtle;
afterlife disdain derange redneck;
devious attentive condemnatory nymph 2nd sou;
astigmatism shine zagging sage auk;
incentive tattle woodrow deposit;
boolean stagnant setback cull objet dust;
elysian stuck temper freethink octile my yea;
trauma endogamous cohesive hay;
applejack ramp squalid beatitude a;
byline novitiate noun rawhide guile;
cutset pig sundown puff stablemen max;
meteoritic sword dose epiphyseal vie;
ceremony.

-M

Free your mind

Re^2: Ode to a random number
created: 2006-06-21 02:10:05
If only it would rhyme!

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re^3: Ode to a random number
created: 2006-06-21 05:55:22
duly scheduled for v0.3

-M

Free your mind

perlmonks.org content © perlmonks.org and ambrus, CountZero, dwildesnl, Moron

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03