> For the complete documentation index, see [llms.txt](https://docs.wem.io/platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wem.io/platform/wemreference/functions/math/random.md).

# Random

{% hint style="info" %}
The **`Random()`** generates a random <mark style="color:green;">number</mark>.

This function is NOT SQL compatible. For more information about SQL compatibility, see our [documentation](/platform/wemreference/sql-compatibility.md).
{% endhint %}

{% hint style="success" %}
Returns a random integral number between 0 or a specified minimum value, and a maximum value.\
Returns <mark style="color:red;">**`Invalid expression`**</mark> if one of the parameter values is not a valid number, ~~or is a negative number, or when a maximum value is 0~~, or when the maximum value is less than the specified minimum value or 0 when only the maximum is specified.

As of version 4.2, the Random function also accepts negative numbers **when both min and max values** are provided - just as long as min < max.
{% endhint %}

{% hint style="warning" %}
This function uses 32-bit Integers, therefore the range of valid parameters is

**-2147483648 and +2147483648**
{% endhint %}

### Syntax

<details>

<summary><code>Random(</code><mark style="color:blue;"><code>max_num</code></mark><code>)</code></summary>

`Random(100)`\
\&#xNAN;*=> 64*

`Random()`\
\&#xNAN;*=> Invalid expression*

`Random(0)`\
\&#xNAN;*=> Invalid expression #* <mark style="color:blue;">`max_num`</mark> *should be greater than 0*

`Random(-10)`\
\&#xNAN;*=> Invalid expression #* <mark style="color:blue;">`max_num`</mark> *should be greater than 0*

</details>

<details>

<summary><code>Random(</code><mark style="color:blue;"><code>min_num, max_num</code></mark><code>)</code></summary>

`Random(10, 100)`\
\&#xNAN;*=> 67*

`Random()`\
\&#xNAN;*=> Invalid expression*

`Random(-10, 10)`\
\&#xNAN;*=> a random value between -10 and 10 (accepted since version 4.2)*

`Random(20, 10)`\
\&#xNAN;*=> Invalid expression #* <mark style="color:blue;">`max_num`</mark> *should be greater than* <mark style="color:blue;">`min_num`</mark>

</details>

### Parameters

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="150" align="center">Required</th><th width="248.15953250810662">Description</th><th data-hidden>Required?</th></tr></thead><tbody><tr><td><mark style="color:blue;"><code>max_num</code></mark></td><td>numeric</td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="2611">☑️</span></td><td>the maximum value of the generated number.</td><td>yes</td></tr><tr><td><mark style="color:blue;"><code>min_num</code></mark></td><td>numeric</td><td align="center"></td><td>the minimum value of the generated number.</td><td>yes</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.wem.io/platform/wemreference/functions/math/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.
