Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: (tye)Re: Transcramble - Random text generator

by blakem (Monsignor)
on Jul 10, 2001 at 11:40 UTC ( #95251=note: print w/replies, xml ) Need Help??


in reply to (tye)Re: Transcramble - Random text generator
in thread Transcramble - Random text generator

And here it is:

from the first Programming Perl (back when it was still pink)

#!/usr/bin/perl # Usage travesty [files] # First analyse the input. while(<>) { # handle article headers and ">>>" quotes. next if /^\./; next if /^From / .. /^$/; next if /^Path: / .. /^$/; s/^\W+//; # Do each word. push(@ary,split(' ')); while ($#ary > 1) { $a = $p; $p = $n; $w = shift(@ary); $n = $num{$w}; if ($n eq '') { push(@word,$w); $n = pack('S',$#word); $num{$w} = $n; } $lookup{$a . $p} .= $n; } } # Now spew out the words, based on the frequencies. If there # is more than one possibility to choose from choose one # randomly. for (;;) { $n = $lookup{$a . $b}; ($foo,$n) = each(lookup) if $n eq ''; # A bootstrap. $n = substr($n,int(rand(length($n))) & 0177776,2); $a = $p; $p = $n; ($w) = unpack('S',$n); $w = $word[$w]; # See if word fits on line; $col += length($w) +1; if ($col >= 65) { $col = 0; print "\n"; } else { print ' '; } print $w; # Paragraph every 10 sentences or so. if ($w =~ /\.$/) { if (rand() < .1) { print "\n"; $col = 80; } } }
p.s. These little gems are the reason I keep that old pink book around.

Replies are listed 'Best First'.
Re: Re: (tye)Re: Transcramble - Random text generator
by Poetic Justice (Monk) on Jul 10, 2001 at 23:26 UTC
    I tried this using a large text file from Writing of the Early Church Father", at Christian Classics Ethereal Library. The results were pretty amazing! Nice that you kept the "old book" around.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://95251]
help
Chatterbox?
[Discipulus]: fore every 2 good old monks that come back, we will accept 1 clinical
[planetscape]: Might be "well, come back!" Discipulus ;-)
[stonecolddevin]: that's a 2.0 k/d ratio, i'll take it
[choroba]: #cbstream still down?
[erix]: yeah, annoying
[choroba]: last ambrus: 1 week ago :-(
[erix]: let's invade Hungary
[planetscape]: darn
[erix]: probably on holiday, the slacker

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2017-06-22 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (530 votes). Check out past polls.