Random file of set length

Matt Alexander plug-discuss@lists.plug.phoenix.az.us
Wed, 11 Sep 2002 17:05:50 -0700 (PDT)


<Matt quickly covers his eyes and runs screaming from Robert's email>



On Wed, 11 Sep 2002, Robert Bushman wrote:

> How about a "random file" of 5 MB?
>
> (yes I know this is some ugly Perl)
>
> #!/usr/bin/perl
>
> @dirs = `find ~/* -type d`;
>
> my $dir = $dirs[ rand( @dirs ) ];
> chomp $dir;
>
> my $numChars = int( rand( 12 ) ) + 1;
> my $extChars = int( rand( 12 ) ) + 1;
>
> my $file = "";
>
> for( 1..$numChars ) { $file .= (a..z)[ rand( 24 ) ]; }
> $file .= ".";
> for( 1..$extChars ) { $file .= (a..z)[ rand( 24 ) ]; }
> my $file = $dir."/".$file;
>
> open( OUT, ">".$file );
> for( 1..5000000 ) { print OUT "."; }
> close( OUT );
> print "wrote 5 million chars to $file.\n";
>
> exit( 0 );