[San-diego-pm] another bug in perl: rand/OSX?

C. Abney cabney at ucsd.edu
Thu Jun 3 09:52:11 CDT 2004


It's platform specific, however... I get completely different behavior
on Sun/sparc or Linux/P4.

Yours,

Charles

On Thu, 2004-06-03 at 07:25, Randal L. Schwartz wrote:
> >>>>> "C" == C Abney <cabney at ucsd.edu> writes:
> 
> C> Maybe my keywords suck and this is a known issue?
> C> Running this script on a Mac OSX gives very unexpected results:
> 
> You can illustrate this well known bug with:
> 
> perl -le 'print rand; fork or exit print rand; fork or exit print rand; fork or exit print rand; print rand'
> 
> You'll get one number from the first rand call (which sets the seed),
> and then the same number from all remaining calls to rand.
> 
> The solution is well known... when you fork, you need to srand manually
> in the child.
> 
> The behavior has nothing to do with OSX.  It's completely generic to Perl.
> I just verified that on my OpenBSD box.
> 
> -- 
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
-- 
Charles Abney
Polymorphism Research Laboratory, 0603
UCSD School of Medicine
9500 Gilman Dr.
La Jolla, CA 92093-0603
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 307 bytes
Desc: This is a digitally signed message part
Url : http://mail.pm.org/pipermail/san-diego-pm/attachments/20040603/b9d597a4/attachment.bin


More information about the San-Diego-pm mailing list