summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/rand.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/stdlib/rand.3')
-rw-r--r--src/lib/libc/stdlib/rand.348
1 files changed, 34 insertions, 14 deletions
diff --git a/src/lib/libc/stdlib/rand.3 b/src/lib/libc/stdlib/rand.3
index a0e7740e66..75395976f8 100644
--- a/src/lib/libc/stdlib/rand.3
+++ b/src/lib/libc/stdlib/rand.3
@@ -13,11 +13,7 @@
13.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the 14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution. 15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software 16.\" 3. Neither the name of the University nor the names of its contributors
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software 17.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission. 18.\" without specific prior written permission.
23.\" 19.\"
@@ -33,25 +29,28 @@
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE. 30.\" SUCH DAMAGE.
35.\" 31.\"
36.\" from: @(#)rand.3 6.7 (Berkeley) 6/29/91 32.\" $OpenBSD: rand.3,v 1.15 2014/04/07 17:57:56 schwarze Exp $
37.\" $Id: rand.3,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $
38.\" 33.\"
39.Dd June 29, 1991 34.Dd $Mdocdate: April 7 2014 $
40.Dt RAND 3 35.Dt RAND 3
41.Os 36.Os
42.Sh NAME 37.Sh NAME
43.Nm rand , 38.Nm rand ,
39.Nm rand_r ,
44.Nm srand 40.Nm srand
45.Nd bad random number generator 41.Nd bad random number generator
46.Sh SYNOPSIS 42.Sh SYNOPSIS
47.Fd #include <stdlib.h> 43.In stdlib.h
48.Ft void 44.Ft void
49.Fn srand "unsigned seed" 45.Fn srand "unsigned int seed"
50.Ft int 46.Ft int
51.Fn rand void 47.Fn rand void
48.Ft int
49.Fn rand_r "unsigned int *seed"
52.Sh DESCRIPTION 50.Sh DESCRIPTION
53.Bf -symbolic 51.Bf -symbolic
54These interfaces are obsoleted by random(3). 52These interfaces are obsoleted by
53.Xr random 3 .
55.Ef 54.Ef
56.Pp 55.Pp
57The 56The
@@ -60,7 +59,7 @@ function computes a sequence of pseudo-random integers in the range
60of 0 to 59of 0 to
61.Dv RAND_MAX 60.Dv RAND_MAX
62(as defined by the header file 61(as defined by the header file
63.Aq Pa stdlib.h ) . 62.In stdlib.h ) .
64.Pp 63.Pp
65The 64The
66.Fn srand 65.Fn srand
@@ -73,13 +72,34 @@ with the same seed value.
73.Pp 72.Pp
74If no seed value is provided, the functions are automatically 73If no seed value is provided, the functions are automatically
75seeded with a value of 1. 74seeded with a value of 1.
75.Pp
76The
77.Fn rand_r
78is a thread-safe version of
79.Fn rand .
80Storage for the seed must be provided through the
81.Fa seed
82argument, and needs to have been initialized by the caller.
76.Sh SEE ALSO 83.Sh SEE ALSO
84.Xr arc4random 3 ,
85.Xr rand48 3 ,
77.Xr random 3 86.Xr random 3
78.Sh STANDARDS 87.Sh STANDARDS
79The 88The
80.Fn rand 89.Fn rand
81and 90and
82.Fn srand 91.Fn srand
83functions 92functions conform to
84conform to
85.St -ansiC . 93.St -ansiC .
94.Pp
95The
96.Fn rand_r
97function conforms to
98.St -p1003.1-2008 .
99.Sh HISTORY
100The functions
101.Fn rand
102and
103.Fn srand
104first appeared in
105.At v3 .