NetBSD Problem Report #476

From gnats  Wed Sep 14 10:03:09 1994
Received: from scrooge.ee.swin.oz.au (scrooge.ee.swin.oz.au [136.186.4.20]) by sun-lamp.cs.berkeley.edu (8.6.9/8.6.9) with ESMTP id KAA13344 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Wed, 14 Sep 1994 10:03:06 -0700
Message-Id: <199409141705.DAA06270@scrooge.ee.swin.oz.au>
Date: Thu, 15 Sep 1994 03:05:31 +1000 (EST)
From: Douglas Thomas Crosher  <dtc@scrooge.ee.swin.oz.au>
To: gnats-bugs@sun-lamp.cs.berkeley.edu
Subject: rand48.3 manual page error over lrand48 and mrand48

>Number:         476
>Category:       lib
>Synopsis:       rand48 manual page inconsistent with operation of lrand48 and mrand48
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnats-admin
>State:          closed
>Class:          doc-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 14 10:05:07 +0000 1994
>Closed-Date:    Sat Sep 17 01:02:13 +0000 1994
>Last-Modified:  
>Originator:     Douglas Crosher
>Release:        
>Organization:
	Swinburne University of technology
>Environment:

System: NetBSD 1.0_BETA : Wed Aug 10 1994

>Description:

>How-To-Repeat:

Read the manual page for rand48, eg. man rand48

Note: 	
     lrand48() and nrand48() return values of type long in the range [-2**31,
     2**31-1]. The high-order (32) bits of r(n+1) are loaded into the returned
     value.

     mrand48() and jrand48() return values of type long in the range [0,
     2**31-1]. The high-order (31) bits of r(n+1) are loaded into the lower
     bits of the returned value, with the topmost (sign) bit set to zero.


Now run the following program:
-=-=-=-
#include <stdlib.h>
#include <stdio.h>

main(){
srand48(123456);

for (;;)
printf("%9x, %9x \n",lrand48(), mrand48());

}
-=-=-=-
Output:
 55caefe0,  f0ce381c 
 1a764ab1,  a1b9c755 
 24eb7a12,   e2d12e1 
 7eb5b0ce,  38e1ce13 
 7b4010d4,  8bd86ab5 
 305f1e5b,  45cdafd0 
  3be407c,  67653957 
 280d5386,   f80c314 
 15d75ba1,  a8c6de47 

Note that lrand48 returns a 31 bit number and mrand48 returns a 32 bit
number, this is consistent with other machines I have tried but
inconsistent with the manual page which describes the opposite
behavior.

>Fix:

Swap the definitions of lrand48 and mrand48 in the manual page
lib/stdlib/rand48.3
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: mycroft 
State-Changed-When: Fri Sep 16 18:02:13 PDT 1994 
State-Changed-Why:  
Fixed. 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.