> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Hex.random

:::info
`Hex.random` is a re-export of ox's [`Hex.random`](https://oxlib.sh/api/Hex/random). Refer to the ox documentation for the full reference.
:::

Generates a random [`Hex.Hex`](/docs/utilities/hex/types#hex) value of the specified length.

## Imports

```ts
import { Hex } from 'viem/utils'
```

## Examples

```ts twoslash
// @noErrors
import { Hex } from 'viem/utils'

const hex = Hex.random(32)
// @log: '0x...'
```

## Definition

```ts
function random(
  length: number,
): Hex
```

## Parameters

### length

* **Type:** `number`

## Return Type

Random [`Hex.Hex`](/docs/utilities/hex/types#hex) value.

`Hex`
