Random file of set length

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


On Wed, 11 Sep 2002, Matt Alexander wrote:

> On Wed, 11 Sep 2002, Randy Kaelber wrote:
>
> > Matt Alexander wrote:
> > >
> > > On Wed, 11 Sep 2002, Gilbert T. Gutierrez, Jr. wrote:
> > >
> > > > I want to create a random file of 5MB. How do I do that?
> > >
> > > dd if=/dev/zero of=somefile bs=1024k count=5
> >
> > Depending on one definition of random ("I need a J. Random 5 meg file")
> > that works, However, another definition ("I need a file with 5 megs of
> > random data") this suggests a slightly different approach:
>
> Yes... I read his question the first way... as in, "I want to make some
> miscellaneous, non-important file of 5MB in size." Ah well, that's what
> makes the English language so much fun. ;-)
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> PLUG-discuss mailing list -
> To subscribe, unsubscribe, or to change you mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>


-----------------------------------------------------------
"These security related updates may disable your ability
to copy and/or play Secure Content and use other software
on your computer." - MS Media Player EULA
-----------------------------------------------------------