GETENTROPY(3) Library Functions Manual GETENTROPY(3)

getentropyfill a buffer with random bytes

#include <unistd.h>

int getentropy(void *buffer, size_t length);

The getentropy () function shall write length bytes of data starting at the location pointed to by . The output shall be unpredictable high quality random data, generated by a cryptographically secure pseudo-random number generator. The maximum permitted value for the length argument is given by the {GETENTROPY_MAX} symbolic constant defined in <limits.h>.

A successful call to getentropy () shall always provide the requested number of bytes of entropy.

Upon successful completion, getentropy () shall return 0; otherwise, -1 shall be returned and set to indicate the error.

The getentropy () function shall fail if:

The value of length is greater than {GETENTROPY_MAX}.

The getentropy () function may fail if:

The system does not provide the necessary source of entropy.

None.

The intended use of this function is to create a seed for other pseudo-random number generators.

The getentropy () function is not a cancellation point. (See V2_chap02(3).)

None.

drand48(3), initstate(3), rand(3)

XBD <limits.h>, <unistd.h>

First released in Issue 8.

June 14, 2024 posix.fail