1502 Remove conversion cruft from manpages
[unleashed.git] / usr / src / man / man3c / rand.3c
blob4fc6754c3bd3f03a34e4ef4a402c1e465417c6ae
1 '\" te
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"
7 .SH NAME
8 rand, srand, rand_r \- simple random-number generator
9 .SH SYNOPSIS
10 .LP
11 .nf
12 #include <stdlib.h>
14 \fBint\fR \fBrand\fR(\fBvoid\fR);
15 .fi
17 .LP
18 .nf
19 \fBvoid\fR \fBsrand\fR(\fBunsigned int\fR \fIseed\fR);
20 .fi
22 .LP
23 .nf
24 \fBint\fR \fBrand_r\fR(\fBunsigned int *\fR\fIseed\fR);
25 .fi
27 .SH DESCRIPTION
28 .sp
29 .LP
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>).
33 .sp
34 .LP
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
42 .sp
43 .LP
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
49 will be generated.
50 .sp
51 .LP
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.
57 .SH USAGE
58 .sp
59 .LP
60 The spectral properties of \fBrand()\fR are limited.  The \fBdrand48\fR(3C)
61 function provides a better, more elaborate random-number generator.
62 .sp
63 .LP
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
66 applications.
67 .SH ATTRIBUTES
68 .sp
69 .LP
70 See \fBattributes\fR(5) for descriptions of the following attributes:
71 .sp
73 .sp
74 .TS
75 box;
76 c | c
77 l | l .
78 ATTRIBUTE TYPE  ATTRIBUTE VALUE
80 Interface Stability     Standard
82 MT-Level        Safe
83 .TE
85 .SH SEE ALSO
86 .sp
87 .LP
88 \fBdrand48\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)