SunOS3.2 rand(3) manual error
ok at quintus
ok at quintus
Sun Nov 27 15:44:23 AEST 1988
The SunOS 3.2 on-line manual page for rand(3v) says:
rand uses a multiplicative congruential random number gen-
erator with period 2**32 to return successive pseudo-random
numbers in the range from 0 to (2**15)-1.
In fact it generates 31-bit integers, as the following test program shows:
main()
{
extern int rand();
extern void srand();
int i;
srand(21345);
for (i = 1; i <= 20; i++) printf("%12d\n", rand());
}
--
This program generates identical results on a Sun-3/60 and a Sequent 386.
The Sequent documentation describes the range correctly.
The SVID specifies 15-bit results. The BSD/SV incompatibility is known, but
it looked as though SunOS 3.2 had adopted the SV definition. Nope, you still
need (rand()&32767) for portability.
More information about the Comp.bugs.4bsd.ucb-fixes
mailing list