# random

Generates random values — strings, numbers, alphanumeric codes, or floating-point numbers. Useful for creating unique identifiers, random codes, and test data.

```liquid
{% assign code = "alphanumeric" | random: 8 %}
{% log code %}
```

#### Syntax

```liquid
{{ type | random }}
{{ type | random: length }}
{{ type | random: length, downcase }}
```

#### Modes

**Alphanumeric string**

Generates a random string of letters and digits.

```liquid
{{ "alphanumeric" | random: 8 }}
```

| Parameter  | Description                             |
| ---------- | --------------------------------------- |
| `length`   | Number of characters (1–20, default: 5) |
| `downcase` | Set to `true` for lowercase only        |

```liquid
{% assign code = "alphanumeric" | random: 10 %}
{% log code %}
```

Output: `aB3xK9mP2n`

```liquid
{% assign code = "alphanumeric" | random: 6, true %}
{% log code %}
```

Output: `k3m8p2`

**Number**

Generates a random integer with the specified number of digits.

```liquid
{{ "number" | random: 6 }}
```

| Parameter | Description                         |
| --------- | ----------------------------------- |
| `length`  | Number of digits (1–20, default: 5) |

```liquid
{% assign pin = "number" | random: 4 %}
{% log pin %}
```

Output: `7284`

**String (letters only)**

Generates a random string of letters only (no digits).

```liquid
{{ "string" | random: 5 }}
```

| Parameter  | Description                             |
| ---------- | --------------------------------------- |
| `length`   | Number of characters (1–20, default: 5) |
| `downcase` | Set to `true` for lowercase only        |

```liquid
{% assign token = "string" | random: 8 %}
{% log token %}
```

Output: `KmPxBnTr`

**Float / Decimal**

Generates a random floating-point number within a range.

```liquid
{{ "float" | random: min, max }}
{{ "decimal" | random: min, max }}
```

| Parameter | Description                |
| --------- | -------------------------- |
| `min`     | Minimum value (default: 0) |
| `max`     | Maximum value (default: 1) |

```liquid
{% assign price = "float" | random: 10, 100 %}
{% log price %}
```

Output: `47.382917`

#### Examples

**Generate a unique order reference:**

```liquid
{% assign ref = "alphanumeric" | random: 12 %}
{% log "REF-" | append: ref %}
```

**Generate a discount code:**

```liquid
{% assign discount_code = "alphanumeric" | random: 8, true %}
{% log "SAVE-" | append: discount_code | upcase %}
```

**Generate a random verification PIN:**

```liquid
{% assign pin = "number" | random: 6 %}
{% log "Your PIN: " | append: pin %}
```

**Generate a random price for testing:**

```liquid
{% assign test_price = "float" | random: 5, 200 %}
{% assign test_price = test_price | round: 2 %}
{% log "Test price: $" | append: test_price %}
```

#### Notes

* Maximum length for strings and numbers is 20 characters/digits
* `"float"` and `"decimal"` are interchangeable — both generate floating-point numbers
* Random values are not cryptographically secure — do not use for passwords or security tokens
* For secure hashing, use `hmac_sha256` or `sha1` instead


---

# Agent Instructions: 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:

```
GET https://docs.datajet-app.com/liquid/filters/random.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
