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

# random\_harvest\_direct(9)

gather entropy from the kernel for the entropy device

Part of [random\_harvest(9)](/random_harvest/9.md).

## NAME

**random\_harvest** – gather entropy from the kernel for the entropy device

## SYNOPSIS

**#include \<sys/types.h\>**

**#include \<sys/random.h\>**

*void*\

**random\_harvest\_direct**(*void \*entropy*, *u\_int size*, *enum esource source*);

*void*\

**random\_harvest\_fast**(*void \*entropy*, *u\_int size*, *enum esource source*);

*void*\

**random\_harvest\_queue**(*void \*entropy*, *u\_int size*, *enum esource source*);

## DESCRIPTION

The **random\_harvest\_\***() functions are used by device drivers and other kernel processes to pass data that is considered (at least partially) stochastic to the entropy device.

The caller should pass a pointer pointing to the “random” data in *entropy*. The argument *size* contains the number of bytes pointed to. The *source* is chosen from one of the values enumerated in *sys/dev/random.h*. and is used to indicate the source of the entropy.

The **random\_harvest\_direct**() variant is used for early harvesting before any multitasking is enabled.

The **random\_harvest\_fast**() variant is used by sources that should not take a performance hit from harvesting, as they are high-rate sources. Some entropy is sacrificed, but the high rate of supply will compensate for this.

The **random\_harvest\_queue**() variant is used for general harvesting and is the default choice for most entropy sources such as interrupts or console events.

Interrupt harvesting has been in part simplified for the kernel programmer. If a device driver registers an interrupt handler with [BUS\_SETUP\_INTR(9)](/BUS_SETUP_INTR/9.md) or [bus\_setup\_intr(9)](/bus_setup_intr/9.md), then it is only necessary to include the INTR\_ENTROPY bit in the *flags* argument to have that interrupt source be used for entropy harvesting. This should be done wherever practicable.

## SEE ALSO

[random(4)](/random/4.md), [BUS\_SETUP\_INTR(9)](/BUS_SETUP_INTR/9.md)

## AUTHORS

The FreeBSD [random(4)](/random/4.md) entropy device and supporting documentation was written by Mark R V Murray.
