Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Feb 2001 04:00:22 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        n@nectar.com (Jacques A. Vidrine)
Cc:        tlambert@primenet.com (Terry Lambert), kris@FreeBSD.ORG (Kris Kennaway), arch@FreeBSD.ORG
Subject:   Re: rand(3) (was Re: cvs commit: ports/astro/xglobe/files patch-random)
Message-ID:  <200102270400.VAA11366@usr05.primenet.com>
In-Reply-To: <20010226211804.A44846@spawn.nectar.com> from "Jacques A. Vidrine" at Feb 26, 2001 09:18:04 PM

next in thread | previous in thread | raw e-mail | index | archive | help
> > > Why do you expect this anyway?
> > 
> > I am a scientist.  Repeatability of experiments is important.
> 
> I meant:  Why do you expect that, for example, Solaris's rand()
> implementation would give the same results as FreeBSD's rand()
> implementation, or that on any other platform?  The algorithm
> is not specified by ISO C, nor by POSIX, nor by SUSv2.

[ ... ]

> The implication being, of course, that if you want your results to be the same
> across platforms, than you need to provide your own PRNG instead of using
> rand().

The 48 bit linear congruential algorithm is a defacto standard for
the implementation across UNIX platforms.  While the standards do
not specify this algorithm, in practice it is there, just as, in
practice, select() does not modify the contents of timeval, even
though the man page permits it to do so, since code would break.

I would be much happier if you were to quote a platform standard
instead of a language standard to permit change.  Realize that C
programs will not necessarily run everywhere without modification,
unless they are simple, or unless the author takes great care in
crafting the code.  Even platform standards have been stretched to,
for example, include NT and VMS as "technically POSIX compliant".

If you can change the underlying implementation of rand(), you
might as well do select() and qsort() (which the manual page
acknowledges is modified in an unspecified way), since technically,
you would be permitted to do so.  The qsort() example is rather
quixotic; the select() example, less so, since the change would in
fact permit higher resolution in timing than is currently permitted
in the context of a select timeout.

Can someone put forth a use for rand() which requires this change
to permit the use to employe rand() instead of its own code?


					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200102270400.VAA11366>