1arc4random(3)              Library Functions Manual              arc4random(3)
2
3
4

NAME

6       arc4random,  arc4random_uniform, arc4random_buf - cryptographically-se‐
7       cure pseudorandom number generator
8

LIBRARY

10       Standard C library (libc, -lc)
11

SYNOPSIS

13       #include <stdlib.h>
14
15       uint32_t arc4random(void);
16       uint32_t arc4random_uniform(uint32_t upper_bound);
17       void arc4random_buf(void buf[.n], size_t n);
18

DESCRIPTION

20       These functions give cryptographically-secure pseudorandom numbers.
21
22       arc4random() returns a uniformly-distributed value.
23
24       arc4random_uniform() returns a uniformly-distributed  value  less  than
25       upper_bound (see BUGS).
26
27       arc4random_buf()  fills  the  memory pointed to by buf, with n bytes of
28       pseudorandom data.
29
30       The rand(3) and drand48(3) families of functions should  only  be  used
31       where  the  quality  of  the  pseudorandom numbers is not a concern and
32       there's a need for repeatability of the results.  Unless you meet  both
33       of those conditions, use the arc4random() functions.
34

RETURN VALUE

36       arc4random() returns a pseudorandom number.
37
38       arc4random_uniform()  returns  a  pseudorandom  number  less  than  up‐
39       per_bound for valid input, or 0 when upper_bound is invalid.
40

ATTRIBUTES

42       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
43       tributes(7).
44
45       ┌────────────────────────────────────────────┬───────────────┬─────────┐
46Interface                                   Attribute     Value   
47       ├────────────────────────────────────────────┼───────────────┼─────────┤
48arc4random(), arc4random_uniform(),         │ Thread safety │ MT-Safe │
49arc4random_buf()                            │               │         │
50       └────────────────────────────────────────────┴───────────────┴─────────┘
51

STANDARDS

53       BSD.
54

HISTORY

56       OpenBSD 2.1, FreeBSD 3.0, NetBSD  1.6,  DragonFly  1.0,  libbsd,  glibc
57       2.36.
58

BUGS

60       An  upper_bound  of  0  doesn't make sense in a call to arc4random_uni‐
61       form().  Such a call will fail, and return 0.  Be careful,  since  that
62       value  is  not less than upper_bound.  In some cases, such as accessing
63       an array, using that value could result in Undefined Behavior.
64

SEE ALSO

66       getrandom(3), rand(3), drand48(3), random(7)
67
68
69
70Linux man-pages 6.04              2023-03-18                     arc4random(3)
Impressum