TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [TCLUG:10346] Perl question
> From: Phil Plumbo [mailto:psp@printwareinc.com]
>
> I'm using this code fragment I stole from on the the O'Reilley Perl books:
>
> @chars = ("A" .. "Z", 0 .. 9);
> $test= join("", @chars[ map {rand @chars} (1 .. 9) ]);
>
> It gives me 9-character "random" strings, nice as you please. The weird
> thing is that they all start with "A". What's up with that?
>
> So far I've only run it on an NT system, on the MS v5.001 Perl
> port (my test
> server).
> I'm in the process of setting up a Linux-based Apache server
> (can't wait) -
> will it behave differently there?
Just a guess, but try calling "srand" first, either by itself or with some
nice unpredictable seed value (I don't know NT Perl at all, so I don't know
if you can use pid's or epoch seconds or other such UNIXisms). I'm guessing
either srand isn't getting called, or it's getting called with some useless
value like the current minute.
If this is correct, it will behave differently under Linux.