Section: Linux Programmer's Manual (3)
getentropy - fill a buffer with random bytes
int getentropy(void *buffer, size_t length);
Feature Test Macro Requirements for glibc (see
bytes of high-quality random data to the buffer starting
at the location pointed to by
The maximum permitted value for the
argument is 256.
A successful call to
always provides the requested number of bytes of entropy.
On success, this function returns zero.
On error, -1 is returned, and
is set appropriately.
Part or all of the buffer specified by
is not in valid addressable memory.
is greater than 256.
An unspecified error occurred while trying to overwrite
with random data.
This kernel version does not implement the
system call required to implement this function.
function first appeared in glibc 2.25.
This function is nonstandard.
It is also present on OpenBSD.
function is implemented using
Whereas the glibc wrapper makes
a cancellation point,
is not a cancellation point.
is also declared in
(No feature test macro need be defined to obtain the declaration from
that header file.)
A call to
may block if the system has just booted and the kernel has
not yet collected enough randomness to initialize the entropy pool.
In this case,
will keep blocking even if a signal is handled,
and will return only once the entropy pool has been initialized.
This page is part of release 5.10 of the Linux
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at