getrandom
TLDR
Get random bytes (shell)
SYNOPSIS
#include <sys/random.h>
ssize_t getrandom(void \*buf, size_t buflen, unsigned int flags);
DESCRIPTION
getrandom() is a Linux system call that fills a buffer with random bytes from the kernel's random number generator. It's the recommended interface for obtaining random data in programs.
Unlike reading from /dev/urandom, getrandom() blocks during early boot until the entropy pool is initialized, ensuring strong randomness.
PARAMETERS
buf
Buffer to receive random bytes.buflen
Number of bytes to read.flags
GRNDRANDOM (use /dev/random) or GRNDNONBLOCK.
FLAGS
GRND_RANDOM - Use /dev/random pool (may block)
GRND_NONBLOCK - Don't block, return error instead
SHELL ALTERNATIVES
dd if=/dev/urandom bs=16 count=1
# Generate random hex
openssl rand -hex 16
# Generate random base64
openssl rand -base64 16
CAVEATS
System call, not a command. Available since Linux 3.17. On older systems, read from /dev/urandom. May block at early boot.
HISTORY
The getrandom() system call was added to Linux kernel 3.17 in 2014 by Theodore Ts'o to address issues with /dev/urandom returning weak random data before the entropy pool was initialized.
SEE ALSO
random(4), urandom(4), openssl-rand(1)


