Lincoln D. Stein has a web page with a travesty generator and the
source:
http://stein.cshl.org/~lstein/mangler.cgi
But I think it generates the travesty word-by-word. Here's an execrable
nth order Markov text generator I whipped out. Be aware that if you're
going to generate a high order travesty you need a lot of text to get
good results.
* * *
$text = "When in the Course of human events, it becomes necessary for
one people to dissolve the political bands which have connected them
with another, and to assume among the powers of the earth, the separate
and equal station to which the Laws of Nature and of Nature's God
entitle them, a decent respect to the opinions of mankind requires that
they should declare the causes which impel them to the separation.";
$order = 5;
# Break the text into chunks and store them in a hash table.
for ( $i = 0; $i < length ( $text ) - $order; $i++ )
{
$h{ substr ( $text, $i, $order ) }++;
}
# Create a list of the text chunks, weighted by occurrence.
foreach $key ( sort ( keys ( %h ) ) )
{
for ( $i = 0; $i < $h{ $key }; $i++ )
{
push ( @a, $key );
}
}
$str = substr ( $text, 0, $order - 1 );
print ( $str );
for ( $i = 0; $i < 1000; $i++ )
{
for ( $j = 0; $j <= $#a; $j++ )
{
if ( $a[ $j ] =~ /$str./ )
{
$first = $j;
last;
}
}
$last = $first;
for ( $j = $first + 1; $j <= $#a; $j++ )
{
if ( $a[ $j ] !~ /$str./ )
{
$last = $j - 1;
last;
}
}
$r = int ( rand ( $last - $first + 1 ) );
print ( substr ( $a[ $first + $r ], $order - 1 ) );
$str = substr ( $a[ $first + $r ], 1 );
}
* * *
H:\>perl travesty.pl
When in the opinions of human events, it becomes necessary for one
people the opinions of human events, it becomes necessary for one people
the Course of Nature's God entitle the earth, them to which the
political bands which impel the separate and to the political bands
which them to dissolve they should decent respect to dissolve the
opinions of the separation to dissolve them to which have connected the
Course of mankind requires that them to the Course of mankind requires
that them with another, and of mankind requires that the opinions of the
political bands which the opinions of Nature's God entitle to them, a
declare them, a decent respect to the separate and to assume among them
to which impel the opinions of Nature's God entitle to dissolve the
causes which they should decent respect to them, a declare the Course of
mankind requires that the earth, them to the separation to they should
declare them with another, and equal station to assume among them to
which have connected the ea