Random file of set length

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Matt Alexander
Date:  
Subject: Random file of set length
<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 );