---
name: "elf_rand"
section: "3"
platform: "linux"
package: "libelf"
version: "0.197-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/elf_rand"
---

# elf\_rand(3)

Set the offset for the next archive member in an ELF file.

## NAME

elf\_rand - Set the offset for the next archive member in an ELF file.

## SYNOPSIS

```
#include <libelf.h>
size_t elf_rand(Elf *elf, size_t offset);
```

## DESCRIPTION

The **elf\_rand**() function sets the current archive member offset for the ELF archive descriptor *elf* to *offset*.

This function is only valid when *elf* refers to an archive descriptor (i.e., its kind is **ELF\_K\_AR**).

Archive member offsets can be acquired from the *Elf\_Arsym* array returned by [**elf\_getarsym**(3)](/elf_getarsym/3.md).

If the archive header at the given offset cannot be parsed or validated, then 0 is returned.

## PARAMETERS

- *elf*

  A pointer to an ELF archive descriptor.

- *offset*

  A byte offset to the archive header, indicating the desired member position.

## RETURN VALUE

Returns the input *offset* if successful. Returns 0 if *elf* is NULL, is not an archive descriptor, or if an error occurs while reading the member at *offset*.

## SEE ALSO

[**elf\_getarsym**(3)](/elf_getarsym/3.md), [**elf\_next**(3)](/elf_next/3.md), [**libelf**(3)](/libelf/3.md), [**elf**(5)](/elf/5.md)

## ATTRIBUTES

| | | |
| --- | --- | --- |
| **Interface** | **Attribute** | **Value** |
| **elf\_rand**() | Thread safety | MT-Safe |

## REPORTING BUGS

Report bugs to \<elfutils-devel@sourceware.org\> or https://sourceware.org/bugzilla/.
