Travis Thornhill wrote:
I need to make strings of variable length for testing inputs.
The strings can contain any letter, say 'a', and I need to be able to create
the string with
255, 256 or any length.
Is there a quick and easy way to do this with perl?
...
This will generate a string of random length between 1 and 256 with random
letters from a to z.
I have only tested it lightly, so the best of luck to you.
use strict;
use warnings;
my ($rand_string, $index);
my @letters = qw( a b c d e f g h i j k l m n o p q r s t u v w x y z );
my $length = int rand( 255+1 );
for (1..$length) {
$index = int rand(scalar @letters-1);
$rand_string .= $letters[$index];
}
print $rand_string, "\n";
--
Flemming Greve Skovengaard The prophecy of the holy Norns
a.k.a Greven, TuxPower The world is doomed to die
<[EMAIL PROTECTED]> Fire in the sky
4011.25 BogoMIPS The end is coming soon
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/