Is there a more efficient way to generate a random file in Perl?

Question!

This is my first Perl script. Ever:

#!/usr/bin/perl

if ($#ARGV < 1) { die("usage: <size_in_bytes> <file_name>\n"); }

open(FILE,">" . $ARGV[0]) or die "Can't open file for writing\n";

# you can control the range of characters here
my $minimum = 32;
my $range = 96;

for ($i=0; $i< $ARGV[1]; $i++) {
    print FILE chr(int(rand($range)) + $minimum);
}

close(FILE);

Its purpose is to generate a file in a specified size filled with random characters.

It works but it is pretty slow. It takes a few seconds to write a 10MB random file.
Does anyone have suggestions/tips on how to make it faster/better? Also feel free to point out common newbie mistakes.



Answers

If you need random numbers from a range, I'm not aware of more efficient way. Your script adjusted to my likings:

#!/usr/bin/perl

use warnings;
use strict;

die("usage: $0 


Write stream data from /dev/random.

#!/usr/bin/perl
use File::Copy;
if ($#ARGV 
By : Incognito


This video can help you solving your question :)
By: admin