perldoc -f srand
----- Original Message -----
From: "meriwether lewis" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, April 05, 2003 10:09 AM
Subject: random sub returns same results...
> Hi Gurus!
>
> I have the following sub which creates a random
> string. Each time I call the sub in my perl
> script it returns a random string which is fine.
> The problem is every time I run the script the
> same strings are returned. I'm running perl
> 5.001 on Windows 2000.
>
> sub RandomStr
> {
> my $i=0;
> my $str="";
> foreach(0..9,a..z,A..Z)
> { $i++;
> $arr[$i]=$_
> }
> for($j=0;$j<rand(30);$j++)
> {
> $str.=$arr[rand(58)+1]
> }
> return $str;
> }
>
> So if I run my script calling the above three
> times I get:
>
> brLNh
> 96
> x9k
>
> If I run it again I get the same three strings.
> Why?
> Is there a better way to get a random string?
>
> Thanks!
>
> Meriwether
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]