Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Feb 2003 11:50:15 -0800 (PST)
From:      Paul Herman <pherman@frenchfries.net>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   docs/48493: missing range information in arc4random() manpage
Message-ID:  <20030220195015.AD2484B0F@frenchfries.net>

next in thread | raw e-mail | index | archive | help

>Number:         48493
>Category:       docs
>Synopsis:       missing range information in arc4random() manpage
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-doc
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Feb 20 12:00:06 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     Paul Herman
>Release:        FreeBSD 4.7-STABLE i386
>Organization:
>Environment:
System: FreeBSD mammoth.eat.frenchfries.net 4.7-STABLE FreeBSD 4.7-STABLE #0: Sat Jan 25 23:29:57 PST 2003 pherman@mammoth.eat.frenchfries.net:/u02/obj/u01/src/sys/mammoth i386

>Description:
   The manpage for arc4random doesn't state the fact that the range is twice
   the traditional RAND_MAX.  This can lead to erroneous results if used
   like the traditional rand()/random() functions.  A short explanation
   of this fact, and a simple example should be added to the manpage.

   This was already discussed on -hackers.  See archive for details.

>How-To-Repeat:
   man arc4random

>Fix:
Index: arc4random.3
===================================================================
RCS file: /u02/ncvs/src/lib/libc/gen/arc4random.3,v
retrieving revision 1.8.2.4
diff -u -r1.8.2.4 arc4random.3
--- arc4random.3	14 Dec 2001 18:33:50 -0000	1.8.2.4
+++ arc4random.3	20 Feb 2003 19:32:58 -0000
@@ -57,7 +57,13 @@
 can be in about
 .if t 2\u\s71700\s10\d
 .if n (2**1700)
-states.
+states. The
+.Fn arc4random
+function returns pseudo-random numbers in the range of 0 to
+.if t 2\u\s731\s10\d\(mi1,
+.if n (2**31)\(mi1,
+and therefore has twice the range of
+.Dv RAND_MAX .
 .Pp
 The
 .Fn arc4random_stir
@@ -73,6 +79,15 @@
 since
 .Fn arc4random
 automatically initializes itself.
+.Sh EXAMPLES
+The following produces a drop-in replacement for the traditional
+.Fn rand
+and
+.Fn random
+functions using
+.Fn arc4random :
+.Bd -literal -offset indent
+#define foo4random()  (arc4random() % ((unsigned)RAND_MAX + 1))
 .Sh SEE ALSO
 .Xr rand 3 ,
 .Xr random 3 ,
>Release-Note:
>Audit-Trail:
>Unformatted:

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




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