use strict; use warnings; use Getopt::Long; use List::Util qw(min); use vars qw/$Fuzz $Words $Word_Size $Strings $String_Size $OverWrite/; exit(main()); BEGIN { $Fuzz=2; $Words=1000; $Word_Size=25; $Strings=100; $String_Size=1000; $OverWrite=0; } sub opts_msg { warn @_,"\nLegal Opts (with defaults):\n\t--fuzz=$Fuzz --words=$Words --strings=$Strings\n". "\t--word_size=$Word_Size --string_size=$String_Size \n". "\t--over_write --verbose\n"; 1; } sub main { $|++; my $help; my $VERBOSE; GetOptions('fuzz=i' => \$Fuzz, 'words=i' => \$Words, 'strings=i' => \$Strings, 'word_size=i' => \$Word_Size, 'string_size=i'=> \$String_Size, 'over_write!' => \$OverWrite, 'verbose!' => \$VERBOSE, 'help' => \$help) or return opts_msg("Bad Option Provided."); return opts_msg() if $help; my @Chars=qw(A C G T); my $file=sprintf "FT-SC%04d-SL%07d-F%02d-WC%07d-WL%03d.fuzztest", #map { $_>=1000 ? int($_/1000)."k" : $_ } $Strings,$String_Size,$Fuzz,$Words,$Word_Size; if (!$OverWrite and -e $file) { warn "Test file '$file' exists already\n"; warn "Use --over_write to force\n"; print $file,"\n"; return 1; } open my $fh,">",$file or die "Error writing to '$file':$!"; warn "Writing '$file'\n" if $VERBOSE; # Header print $fh '$Fuzz,$Words,$Word_Size,$Strings,$String_Size,$chars',"\n"; print $fh "$Fuzz,$Words,$Word_Size,$Strings,$String_Size,",@Chars,"\n"; # Words my @words; my $count=$String_Size/$Word_Size/2; warn "With $Words words of $Word_Size random chars: (@Chars)\n" if $VERBOSE; for (1..$Words) { my $str=join "",map { $Chars[rand @Chars] } 1..$Word_Size; if (@words<$count) { push @words,$str; } else { $words[rand @words]=$str unless int rand $count/2; } print $fh $str,"\n"; } print $fh "---\n"; # Strings warn "And $Strings random strings of length $String_Size\n" if $VERBOSE; for (1..$Strings) { my $str="A" x $String_Size; substr($str,$_,1,$Chars[rand @Chars]) for 0..$String_Size-1; for (1..$count) { my $p=int rand($String_Size-$Word_Size); my $w=$words[rand @words]; substr($w,int(rand length $w),1)=$Chars[rand @Chars] for 1..rand $Fuzz+1; substr($str,$p,$Word_Size,$w); } print $fh $str,"\n" } close $fh or die "Failed to close '$file'\n"; warn "Done.\n" if $VERBOSE; print $file,"\n"; return 0; }