---
title: randomstr
summary: null
url: >-
  https://www.fastly.com/documentation/reference/vcl/functions/randomness/randomstr
---

```
STRING randomstr(INTEGER len, STRING characters?)
```

**Available in:** all subroutines

Returns a random string of length `len` containing characters from the
optionally supplied string `characters`.

If `characters` is not supplied, this function uses characters from the
following set of 64: `a-zA-Z0-9-_`.

This does not use secure random functions and should not be used for 
cryptographic purposes.

This function is not prefixed with the `std.` namespace.

## Example

```vcl
set req.http.X-RandomHexNum = randomstr(8, "1234567890abcdef");
```
