Forum Moderators: coopster & phranque

Message Too Old, No Replies

random number generator

         

scoobie

11:13 am on Dec 13, 2005 (gmt 0)

10+ Year Member



Hi,

i am trying to generate an alpha-numeric number of size 5 using the perl rand function and print it to the screen.
i tried the following code but can't get it to work:

#my @alphanum = ( "A" .. "Z", "a" .. "z", 0 .. 9);
#my $random = join("", @alphanum map { rand @alphanum } ( 1 .. 5 ) ]);

print $random;

can anybody help,

thanks in advanced

scoobie.

bennymack

11:30 pm on Dec 13, 2005 (gmt 0)

10+ Year Member



One linerized:
perl -e '@alphanum=( 'A'..'Z','a'..'z',0..9);print for (map($alphanum[rand($#alphanum)],(1..5)));print"\n";'

Equivalent to:
#!/usr/bin/perl -w
use strict;

my @alphanum = ( 'A' .. 'Z', 'a' .. 'z', 0 .. 9);
my $random = join('', map($alphanum[rand($#alphanum)],(1..5)));

print "$random\n";

scoobie

11:58 pm on Dec 15, 2005 (gmt 0)

10+ Year Member



thanks for you help.