# man > RAND(7SSL)

---
type: CommandReference
command: RAND
mode: man
section: 7SSL
source: man-pages
---

## Quick Reference
- `RAND_bytes(buf, n)` — Fill buffer with cryptographically secure random bytes; returns 1 on success, 0 on failure.
- `RAND_priv_bytes(buf, n)` — Fill buffer with random bytes for **secret** values (separate CSPRNG instance).
- `RAND_get0_primary()` — Access the default primary DRBG context (advanced use).
- `EVP_RAND` — Replace or extend the default random generator implementation (expert only).

## Name
RAND — the OpenSSL pseudo‑random number generator

## Synopsis
c
#include <openssl/rand.h>
The `RAND` API provides a cryptographically secure pseudo‑random number generator (CSPRNG). The default implementation is based on the NIST SP 800‑90A DRBG model and seeds / reseeds itself automatically using operating‑system trusted sources.

## Options
- `RAND_bytes(unsigned char *buf, int num)` — Generates `num` random bytes into `buf`. On success returns 1; on failure (e.g., no trusted seed source) returns 0 and the CSPRNG may enter an error state until reseeded.
- `RAND_priv_bytes(unsigned char *buf, int num)` — Like `RAND_bytes` but uses a dedicated CSPRNG instance intended for values that must stay secret (private keys, master secrets). Does **not** produce “better” randomness, but limits exposure of internal state.
- `RAND_get0_primary()` — Returns the `EVP_RAND_CTX` of the primary DRBG. Intended for advanced users who need direct access to the DRBG configuration.
- `EVP_RAND` — Engine framework that allows replacing the default random generator with a custom implementation. Changing the default is rarely needed and strongly discouraged without deep cryptographic understanding.

## Examples
c
unsigned char buf[16];
if (RAND_bytes(buf, sizeof(buf)) != 1) {
    /* handle error – randomness not available */
}
For secret values, replace `RAND_bytes` with `RAND_priv_bytes`.

## See Also
- [RAND_bytes(3)](https://www.chedong.com/phpMan.php/man/bytes/3/markdown)
- [RAND_priv_bytes(3)](https://www.chedong.com/phpMan.php/man/bytes/3/markdown)
- [EVP_RAND(3)](https://www.chedong.com/phpMan.php/man/RAND/3/markdown)
- [RAND_get0_primary(3)](https://www.chedong.com/phpMan.php/man/primary/3/markdown)
- [EVP_RAND(7)](https://www.chedong.com/phpMan.php/man/RAND/7/markdown)