2 .\" Copyright 1989 AT&T. Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH RAND 3C "May 19, 2004"
8 rand, srand, rand_r \- simple random-number generator
14 \fBint\fR \fBrand\fR(\fBvoid\fR);
19 \fBvoid\fR \fBsrand\fR(\fBunsigned int\fR \fIseed\fR);
24 \fBint\fR \fBrand_r\fR(\fBunsigned int *\fR\fIseed\fR);
30 The \fBrand()\fR function uses a multiplicative congruential random-number
31 generator with period 2^32 that returns successive pseudo-random numbers in the
32 range of 0 to \fBRAND_MAX\fR (defined in <\fBstdlib.h\fR>).
35 The \fBsrand()\fR function uses the argument \fIseed\fR as a seed for a new
36 sequence of pseudo-random numbers to be returned by subsequent calls to
37 \fBrand()\fR. If \fBsrand()\fR is then called with the same \fIseed\fR value,
38 the sequence of pseudo-random numbers will be repeated. If \fBrand()\fR is
39 called before any calls to \fBsrand()\fR have been made, the same sequence will
40 be generated as when \fBsrand()\fR is first called with a \fIseed\fR value of
44 The \fBrand_r()\fR function has the same functionality as \fBrand()\fR except
45 that a pointer to a seed \fIseed\fR must be supplied by the caller. If
46 \fBrand_r()\fR is called with the same initial value for the object pointed to
47 by seed and that object is not modified between successive calls to
48 \fBrand_r()\fR, the same sequence as that produced by calls to \fBrand()\fR
52 The \fBrand()\fR and \fBsrand()\fR functions provide per-process pseudo-random
53 streams shared by all threads. The same effect can be achieved if all threads
54 call \fBrand_r()\fR with a pointer to the same seed object. The \fBrand_r()\fR
55 function allows a thread to generate a private pseudo-random stream by having
56 the seed object be private to the thread.
60 The spectral properties of \fBrand()\fR are limited. The \fBdrand48\fR(3C)
61 function provides a better, more elaborate random-number generator.
64 When compiling multithreaded applications, the \fB_REENTRANT\fR flag must be
65 defined on the compile line. This flag should be used only in multithreaded
70 See \fBattributes\fR(5) for descriptions of the following attributes:
78 ATTRIBUTE TYPE ATTRIBUTE VALUE
80 Interface Stability Standard
88 \fBdrand48\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)