> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man9/random_harvest.9.md).

# random\_harvest.9

`random_harvest` — 为熵设备从内核收集熵

## 名称

`random_harvest`

## 概要

```c
#include <sys/types.h>
```

```c
#include <sys/random.h>
```

```c
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)
```

## 描述

`random_harvest_*` 函数由设备驱动程序和其他内核进程使用，用于将认为（至少部分）随机的数据传递给熵设备。

调用者应在 `entropy` 中传递指向“随机”数据的指针。参数 `size` 包含所指向的字节数。`source` 从 `sys/dev/random.h` 中枚举的值之一中选择，用于指示熵的来源。

`random_harvest_direct` 变体用于在启用任何多任务处理之前的早期收集。

`random_harvest_fast` 变体由不应因收集而遭受性能损失的源使用，因为它们是高速率源。会牺牲一些熵，但高速率的供应将补偿这一点。

`random_harvest_queue` 变体用于一般收集，是大多数熵源（如中断或控制台事件）的默认选择。

中断收集已在一定程度上为内核程序员简化。如果设备驱动程序使用 [BUS\_SETUP\_INTR(9)](/man/man9/bus_setup_intr.9.md) 或 bus\_setup\_intr(9) 注册中断处理程序，则只需在 `flags` 参数中包含 `INTR_ENTROPY` 位即可使该中断源用于熵收集。应在可行的任何地方执行此操作。

## 参见

[random(4)](/man/man4/random.4.md), [BUS\_SETUP\_INTR(9)](/man/man9/bus_setup_intr.9.md)

## 作者

FreeBSD [random(4)](/man/man4/random.4.md) 熵设备及相关文档由 Mark R V Murray 编写。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man9/random_harvest.9.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
