Merge commit '9276b3991ba20d5a5660887ba81b0bc7bed25a0c'
[unleashed.git] / share / man / man3c / rand.3c
blobd3949f3cde40e424b4253c10005e3fc916e5b579
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 "Feb 11, 2015"
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 .LP
29 The \fBrand()\fR function uses a multiplicative congruential random-number
30 generator with period 2^32 that returns successive pseudo-random numbers in the
31 range of 0 to \fBRAND_MAX\fR (defined in <\fBstdlib.h\fR>).
32 .sp
33 .LP
34 The  \fBsrand()\fR function uses the argument \fIseed\fR as a seed for a new
35 sequence of pseudo-random numbers to be returned by subsequent calls to
36 \fBrand()\fR. If \fBsrand()\fR is then called with the same \fIseed\fR value,
37 the sequence of pseudo-random numbers will be repeated.  If \fBrand()\fR is
38 called before any calls to \fBsrand()\fR have been made, the same sequence will
39 be generated as when \fBsrand()\fR is first called with a \fIseed\fR value of
41 .sp
42 .LP
43 The \fBrand_r()\fR function has the same functionality as \fBrand()\fR except
44 that a pointer to a seed  \fIseed\fR must be supplied by the caller. If
45 \fBrand_r()\fR is called with the same initial value for the object pointed to
46 by seed and that object is not modified between successive calls to
47 \fBrand_r()\fR, the same sequence as that produced by calls to \fBrand()\fR
48 will be generated.
49 .sp
50 .LP
51 The \fBrand()\fR and \fBsrand()\fR functions provide per-process pseudo-random
52 streams shared by all threads. The same effect can be achieved if all threads
53 call \fBrand_r()\fR with a pointer to the same seed object. The \fBrand_r()\fR
54 function allows a thread to generate a private pseudo-random stream by having
55 the seed object be private to the thread.
56 .SH USAGE
57 .LP
58 The spectral properties of \fBrand()\fR are limited.  The \fBarc4random\fR(3C)
59 function provides a better, more elaborate random-number generator.
60 .SH ATTRIBUTES
61 .LP
62 See \fBattributes\fR(5) for descriptions of the following attributes:
63 .sp
65 .sp
66 .TS
67 box;
68 c | c
69 l | l .
70 ATTRIBUTE TYPE  ATTRIBUTE VALUE
72 Interface Stability     Standard
74 MT-Level        Safe
75 .TE
77 .SH SEE ALSO
78 .LP
79 \fBarc4random\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)