---
name: "getentropy"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/getentropy/3"
---

# getentropy(3)

get entropy

## NAME

**getentropy** – get entropy

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<unistd.h\>**

*int*\

**getentropy**(*void \*buf*, *size\_t buflen*);

## DESCRIPTION

**getentropy**() fills a buffer with high-quality random data.

The maximum *buflen* permitted is 256 bytes.

If it does not produce an error, **getentropy**() always provides the requested number of bytes of random data.

Similar to reading from */dev/urandom* just after boot, **getentropy**() may block until the system has collected enough entropy to seed the CSPRNG.

## IMPLEMENTATION NOTES

The **getentropy**() function is implemented using [getrandom(2)](/getrandom/2.md).

## RETURN VALUES

The **getentropy()** function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

## ERRORS

**getentropy**() will succeed unless:

- \[EFAULT\]

  The *buf* parameter points to an invalid address.

- \[EINVAL\]

  Too many bytes requested.

## SEE ALSO

[getrandom(2)](/getrandom/2.md), [arc4random(3)](/arc4random/3.md), [random(4)](/random/4.md)

## STANDARDS

**getentropy**() conforms to IEEE Std 1003.1-2024 (“POSIX.1”).

## HISTORY

The **getentropy**() function appeared in OpenBSD 5.6. The FreeBSD libc compatibility shim first appeared in FreeBSD 12.0.
