jffusion wrote at Tue, 09 Jul 2002 17:33:35 +0200:

> Hi
> 
> I have my script to generate a random username and password and print it in the 
>browser window
> 
> print 'Username: ', random_string(), "\n";
> print 'Password: ', random_string(), "\n";
> 
> sub random_string {
> 
>   my($string) = '';
>   my($length) = 8;
>   my(@chars) = ('A' .. 'Z', 'a' .. 'z', 0 .. 9);
>   while (length($string) != $length) {
>     $string .= $chars[ rand($#chars) ];
>   }
>   return($string);
> }
> }

I would be really too lazy to write my own random routine.
Just have a look to String::Random from CPAN.

However it seems that there's a bug in your random_routine, too.
rand($#chars) gives a random number in the range of 
0 .. $#chars-1
what will mean, there's never a 9 in your random string.
You surely meant
$string .= $chars[ rand @chars ];


Greetings,
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to