← 返回命令列表

Linux command

getrandom 命令

文本

涉及管道、覆盖或删除,执行前请先确认路径和参数。

常用示例

Get random bytes (shell)

head -c [16] /dev/urandom | xxd

Get random bytes (C function)

getrandom(buffer, length, flags)

说明

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.

FAQ

What is the getrandom command used for?

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.

How do I run a basic getrandom example?

Run `head -c [16] /dev/urandom | xxd` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

Where can I find more getrandom examples?

This page includes 2 examples for getrandom, plus related commands for nearby Linux tasks.