]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/arc4random.3
man*/: ffix (un-bracket tables)
[thirdparty/man-pages.git] / man3 / arc4random.3
CommitLineData
82365306 1'\" t
848404fe
AC
2.\" Copyright (C) 2023 Alejandro Colomar <alx@kernel.org>
3.\"
4.\" SPDX-License-Identifier: Linux-man-pages-copyleft
5.\"
6.TH arc4random 3 (date) "Linux man-pages (unreleased)"
7.SH NAME
8arc4random, arc4random_uniform, arc4random_buf
9\- cryptographically-secure pseudorandom number generator
10.SH LIBRARY
11Standard C library
b428a1b9 12.RI ( libc ", " \-lc )
848404fe
AC
13.SH SYNOPSIS
14.nf
15.B #include <stdlib.h>
16.PP
17.B uint32_t arc4random(void);
18.BI "uint32_t arc4random_uniform(uint32_t " upper_bound );
19.BI "void arc4random_buf(void " buf [. n "], size_t " n );
20.fi
21.SH DESCRIPTION
477c35bc 22These functions give cryptographically-secure pseudorandom numbers.
848404fe
AC
23.PP
24.BR arc4random ()
25returns a uniformly-distributed value.
26.PP
27.BR arc4random_uniform ()
28returns a uniformly-distributed value less than
29.I upper_bound
3638ab3f 30(see BUGS).
848404fe
AC
31.PP
32.BR arc4random_buf ()
33fills the memory pointed to by
34.IR buf ,
35with
36.I n
477c35bc 37bytes of pseudorandom data.
848404fe
AC
38.PP
39The
40.BR rand (3)
41and
42.BR drand48 (3)
43families of functions should only be used where
477c35bc 44the quality of the pseudorandom numbers is not a concern
848404fe
AC
45.I and
46there's a need for repeatability of the results.
47Unless you meet both of those conditions,
48use the
49.BR arc4random ()
50functions.
51.SH RETURN VALUE
52.BR arc4random ()
477c35bc 53returns a pseudorandom number.
848404fe
AC
54.PP
55.BR arc4random_uniform ()
477c35bc 56returns a pseudorandom number less than
848404fe
AC
57.I upper_bound
58for valid input, or
59.B 0
60when
61.I upper_bound
62is invalid.
63.SH ATTRIBUTES
64For an explanation of the terms used in this section, see
65.BR attributes (7).
848404fe
AC
66.TS
67allbox;
68lbx lb lb
69l l l.
70Interface Attribute Value
71T{
9e54434e
BR
72.na
73.nh
848404fe
AC
74.BR arc4random (),
75.BR arc4random_uniform (),
76.BR arc4random_buf ()
77T} Thread safety MT-Safe
78.TE
848404fe
AC
79.sp 1
80.SH STANDARDS
179cc19e
AC
81BSD.
82.SH HISTORY
83OpenBSD 2.1,
84FreeBSD 3.0,
85NetBSD 1.6,
86DragonFly 1.0,
87libbsd,
88glibc 2.36.
3638ab3f 89.SH BUGS
848404fe
AC
90An
91.I upper_bound
92of
93.B 0
94doesn't make sense in a call to
95.BR arc4random_uniform ().
96Such a call will fail, and return
97.BR 0 .
98Be careful,
99since that value is
100.I not
101less than
102.IR upper_bound .
103In some cases,
104such as accessing an array,
105using that value could result in Undefined Behavior.
106.SH SEE ALSO
107.BR getrandom (3),
108.BR rand (3),
109.BR drand48 (3),
110.BR random (7)