getrandom(2) System Calls Manual getrandom(2) getrandom - C (libc, -lc) #include ssize_t getrandom(size_t size; void buf[size], size_t size, unsigned int flags); The getrandom() system call fills the buffer pointed to by buf with up to size random bytes. These bytes can be used to seed user-space random number generators or for cryptographic purposes. , getrandom() urandom (. ., /dev/urandom). flags. urandom , 256 , , . . , , EINTR. urandom , getrandom() , flags GRND_NONBLOCK. flags , : GRND_RANDOM If this bit is set, then random bytes are drawn from the random source (i.e., the same source as the /dev/random device) instead of the urandom source. The random source is limited based on the entropy that can be obtained from environmental noise. If the number of available bytes in the random source is less than requested in size, the call returns just the available random bytes. If no random bytes are available, the behavior depends on the presence of GRND_NONBLOCK in the flags argument. GRND_NONBLOCK , random getrandom() , , urandom , . GRND_NONBLOCK, getrandom() , -1 errno EAGAIN. On success, getrandom() returns the number of bytes that were copied to the buffer buf. This may be less than the number of bytes requested via size if either GRND_RANDOM was specified in flags and insufficient entropy was present in the random source or the system call was interrupted by a signal. -1, errno . EAGAIN , getrandom() , GRND_NONBLOCK. EFAULT , buf, . EINTR ; read(2) <<>> SA_RESTART signal(7). EINVAL flags . ENOSYS glibc getrandom() , . Linux. Linux 3.17, glibc 2.25. , , random(7). /dev/random /dev/urandom, getrandom() . , getrandom() , chroot(2) /dev (, ) , . Linux 3.19 : o When reading from the urandom source, a maximum of 32Mi-1 bytes is returned by a single call to getrandom() on systems where int has a size of 32 bits. o random 512 . urandom (GRND_RANDOM ), getrandom() , ( GRND_NONBLOCK). ( 256), getrandom() , buf. random ( GRND_RANDOM), getrandom() , - ( GRND_NONBLOCK). The behavior when a call to getrandom() that is blocked while reading from the urandom source is interrupted by a signal handler depends on the initialization state of the entropy buffer and on the request size, size. If the entropy is not yet initialized, then the call fails with the EINTR error. If the entropy pool has been initialized and the request size is large (size > 256), the call either succeeds, returning a partially filled buffer, or fails with the error EINTR. If the entropy pool has been initialized and the request size is small (size <= 256), then getrandom() will not fail with EINTR. Instead, it will return all of the bytes that have been requested. random ( EINTR). getrandom() (<= 256 ) urandom -- . The special treatment of small values of size was designed for compatibility with OpenBSD's getentropy(3), which is nowadays supported by glibc. The user of getrandom() must always check the return value, to determine whether either an error occurred or fewer bytes than requested were returned. In the case where GRND_RANDOM is not specified and size is less than or equal to 256, a return of fewer bytes than requested should never happen, but the careful programmer will check for this anyway! Linux 3.19 : o , getrandom() , . getentropy(3), random(4), urandom(4), random(7), signal(7) () Azamat Hackimov , Dmitry Bolkhovskikh , Vladislav , Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. Linux 6.17 8 2026 . getrandom(2)