getentropy(3)
๐ getentropy(3) โ bestie, let's get you some random bytes ๐
okay so this is the manual page for getentropy, a lil function from the Library Functions Manual, and it is honestly one of the most wholesome functions in libc because it just... gives you randomness. like, that's the whole bit. no drama, no config, no surprises. โจ
๐ธ NAME ๐ธ
getentropy โ fill a buffer with random bytes ๐ฒ
๐ LIBRARY ๐
Standard C library (libc, -lc)
โจ SYNOPSIS โจ
#include <unistd.h>
int getentropy(size_t length;
void buffer[length], size_t length);
๐ Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
getentropy():
_DEFAULT_SOURCE
yeah bestie, that's the whole secret handshake. define _DEFAULT_SOURCE and glibc will let you in. ๐ซถ
๐ DESCRIPTION ๐
The getentropy() function writes length bytes of high-quality random data to the buffer starting at the location pointed to by buffer. it's giving "cryptographically respectable, no notes" energy, fr fr. ๐ฅ
The maximum permitted value for the length argument is 256. that's the ceiling. do not test it. ๐
A successful call to getentropy() always provides the requested number of bytes of entropy. not "maybe", not "some", not "best effort" โ always. periodt. ๐
๐ฆ RETURN VALUE ๐ฆ
- On success, this function returns zero. ๐
- On error,
-1is returned, anderrnois set to indicate the error.
๐ ERRORS ๐
EFAULTโ part or all of the buffer specified bybufferandlengthis not in valid addressable memory. girl, that memory is not there. ๐ญEIOโlengthis greater than256. (yeah, both of the EIOs in this list are real, don't merge them, i'm watching ๐)EIOโ an unspecified error occurred while trying to overwritebufferwith random data.ENOSYSโ this kernel version does not implement thegetrandom(2)system call required to implement this function. ancient kernel behavior honestly. ๐
โญ STANDARDS โญ
POSIX.1-2024. she's standard, she's official, she's on the list. ๐
๐ง HISTORY ๐ง
OpenBSD 5.6, glibc 2.25, FreeBSD 12.0, POSIX.1-2024. a whole timeline. iconic of her honestly. ๐ธ
๐ NOTES ๐
The getentropy() function is implemented using getrandom(2). that's the machinery under the hood, iykyk. ๐ง
Whereas the glibc wrapper makes getrandom(2) a cancelation point, getentropy() is not a cancelation point. write that down, bestie, it matters. ๐
getentropy() is also declared in <sys/random.h>. (No feature test macro need be defined to obtain the declaration from that header file.) so if you're pulling it from there, no _DEFAULT_SOURCE ritual required. โจ
A call togetentropy()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,getentropy()will keep blocking even if a signal is handled, and will return only once the entropy pool has been initialized.
like... she will wait. no cap. signals cannot sway her. she returns when the vibes are ready and not one second sooner. ๐ซถ
๐ SEE ALSO ๐
getrandom(2), urandom(4), random(7)
and that's the page, bestie!! ๐ this one came from Linux man-pages 6.20, dated 2026-04-21 โ so go forth, fill your buffers with exactly 256 bytes or fewer of certified premium randomness, and slay. ๐๐
โจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 2017, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms