From 5b475602ef15f3797b2bebc8b0b32e05bf0078ac Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Mon, 3 Mar 2008 16:51:35 +0000 Subject: [PATCH] Recommend use or random_r(3) for multithreaded appliucations that need independent, reproducible sequences of random numbers. Move references to "The Art of Computer Programming" and "Numerical Recipes", formerly in rand(3), to this page. Add drand48(93) to SEE ALSO list. --- man3/random.3 | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/man3/random.3 b/man3/random.3 index 87634cb56..e3944c875 100644 --- a/man3/random.3 +++ b/man3/random.3 @@ -28,7 +28,7 @@ .\" Modified Sat Jul 24 18:13:39 1993 by Rik Faith (faith@cs.unc.edu) .\" Modified Sun Aug 20 21:47:07 2000, aeb .\" -.TH RANDOM 3 2007-07-26 "GNU" "Linux Programmer's Manual" +.TH RANDOM 3 2008-03-07 "GNU" "Linux Programmer's Manual" .SH NAME random, srandom, initstate, setstate \- random number generator .SH SYNOPSIS @@ -54,7 +54,7 @@ Feature Test Macro Requirements for glibc (see .BR srandom (), .BR initstate (), .BR setstate (): -_SVID_SOURCE || |_BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 +_SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 .ad b .SH DESCRIPTION The @@ -137,6 +137,27 @@ Current "optimal" values for the size of the state array \fIn\fP are the nearest known amount. Using less than 8 bytes will cause an error. +.PP +This function should not be used in cases where multiple threads use +.BR random () +and the behavior should be reproducible. +Use +.BR random_r (3) +for that purpose. +.PP +Random-number generation is a complex topic. +.I Numerical Recipes in C: The Art of Scientific Computing +(William H. Press, Brian P. Flannery, Saul A. Teukolsky, William +T. Vetterling; New York: Cambridge University Press, 2007, 3rd ed.) +provides an excellent discussion of practical random-number generation +issues in Chapter 7 (Random Numbers). +.PP +For a more theoretical discussion which also covers many practical issues +in depth, see Chapter 3 (Random Numbers) in Donald E. Knuth's +.IR "The Art of Computer Programming" , +volume 2 (Seminumerical Algorithms), 2nd ed.; Reading, Massachusetts: +Addison-Wesley Publishing Company, 1981. .SH "SEE ALSO" +.BR drand48 (3), .BR rand (3), .BR srand (3)