#! /usr/bin/perl # Copyright (c) 2005 Michael H. Burkhardt, All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. All advertising materials mentioning features or use of this software # must display the following acknowledgement: # This product includes software developed by Michael H. Burkhardt # 4. The name of Michael H. Burkhardt may not be used to endorse or promote # products derived from this software without specific prior written # permission. # # THIS SOFTWARE IS PROVIDED BY MICHAEL H. BURKHARDT ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL MICHAEL H. BURKHARDT BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. use Getopt::Std; getopts('eo:',\%opt); # GLOBAL VARIABLES my @mega; my $megalen; my $sow = "ttttttttttttttttaaaaaaaaaaaaaaaaiiiiiiiissssssssoooooooccccccmmmmffffppppwwwwbdeghjklnqruvxyz"; $sowlen = length($sow); my $eow = "eeeeeeeeeeeeeeeeeeessssssssssssssdddddddddtttttttttnnnnnnnnyyyyyyyrrrrrrrooooolllllffffabcghijkmpqsuvwxyz"; $eowlen = length($eow); $outfile = ( $opt{'o'} ) ? $opt{'o'} : "outfile.txt"; # USAGE $USAGE = < 2048 ) { die "Let's don't get crazy now.\n"; } $bytes2write = int($MB * $megs2write); print "Attempting to write ${bytes2write} bytes to ${outfile}\n"; open(OUT,">${outfile}"); $byteswritten = 0; while ( $byteswritten < $bytes2write ) { $r = ( $opt{'e'} ) ? generateLineEng() : randomString(); $byteswritten += length($r); print OUT $r, "\n"; } close(OUT); # INITIALIZE THE MEGASTRING sub initMega() { my @alphabet = qw/ a b c d e f g h i j k l m n o p q r s t u v w x y z /; my @freq = qw/ 82 15 28 43 127 22 20 61 70 2 8 40 24 67 75 19 1 60 63 91 28 10 24 2 20 1 /; my $i; my $j; for ( $i = 0 ; $i < scalar(@alphabet) ; $i++ ) { for ( $j = 0 ; $j < $freq[$i] ; $j++ ) { push(@mega,$alphabet[$i]); } } push(@mega,1,2,3,4,5,6,7,8,9,0); $megalen = scalar(@mega); } # generateLine() # generate a line of text that looks like English sub generateLineEng() { $line = ""; while ( length($line) < 80 ) { if ( length($line) > 0 ) { $line .= " "; } $wordlen = int(rand() * 5) + 1; $line .= substr($sow,int(rand() * $sowlen),1); for ( $j = 0 ; $j < $wordlen ; $j++ ) { $line .= $mega[int(rand() * $megalen)]; } $line .= substr($eow,int(rand() * $eowlen),1); } return(substr($line,0,79)); } # randomString() # generate a line of random text 75 characters long sub randomString() { $rstr = ""; for ( $i = 0 ; $i < 79 ; $i++ ) { $rstr .= chr(32 + int(95 * rand())); } return($rstr); }