tail head cat sleep
QR code linking to this page

Manual Pages  — GETRANDOM


getrandom – get random data



Standard C Library (libc, -lc)


#include <sys/random.h>

getrandom(void *buf, size_t buflen, unsigned int flags);


getrandom() fills buf with up to buflen bytes of random data.

The flags argument may include zero or more of the following:
GRND_NONBLOCK Return EAGAIN instead of blocking, if the random(4) device has not yet been seeded. By default, getrandom() will block until the device is seeded.
GRND_RANDOM This flag does nothing on FreeBSD . /dev/random and /dev/urandom are identical.

If the random(4) device has been seeded, reads of up to 256 bytes will always return as many bytes as requested and will not be interrupted by signals.


Upon successful completion, the number of bytes which were actually read is returned. For requests larger than 256 bytes, this can be fewer bytes than were requested. Otherwise, -1 is returned and the global variable errno is set to indicate the error.


The getrandom() operation returns the following errors:
  The ‘GRND_NONBLOCK’ flag was set and the random(4) device was not yet seeded.
  The buf parameter points to an invalid address.
  The sleep was interrupted by a signal.
  An invalid flags was specified.
  The requested buflen was larger than IOSIZE_MAX.


arc4random(3), getentropy(3), random(4)


getentropy() is non-standard. It is present in Linux.


The getrandom() system call first appeared in FreeBSD 12.0 .

GETRANDOM (2) February 24, 2018

tail head cat sleep
QR code linking to this page

Please direct any comments about this manual page service to Ben Bullock. Privacy policy.

Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems.
— Jamie Zawinski