LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

getrandom

kernel random number generator interface

TLDR

Get random bytes (shell)
$ head -c [16] /dev/urandom | xxd
copy
Get random bytes (C function)
$ getrandom(buffer, length, flags)
copy

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

$ 0             - Default, blocks until entropy available
GRND_RANDOM   - Use /dev/random pool (may block)
GRND_NONBLOCK - Don't block, return error instead
copy

SHELL ALTERNATIVES

$ # Read random bytes
dd if=/dev/urandom bs=16 count=1

# Generate random hex
openssl rand -hex 16

# Generate random base64
openssl rand -base64 16
copy

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

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid