# generateRandomID

## `generateRandomID` Function

The `generateRandomID` function returns a **randomly generated string ID** based on a given **pattern**. It is useful for creating unique identifiers dynamically within server-side variables.

***

### Purpose

Use this function to:

* Generate random session, user, or transaction IDs
* Append randomized suffixes or prefixes to strings
* Simulate identifiers in test setups or fallback mechanisms

***

### Function Definition

| Property          | Description                  |
| ----------------- | ---------------------------- |
| **Function Name** | `this.generateRandomID`      |
| **Type**          | `function`                   |
| **Available In**  | Server-Side Variables        |
| **Returns**       | `string` (randomized result) |

***

### Parameters

| Parameter | Description                                                                                  | Type     | Required                                      | Example            |
| --------- | -------------------------------------------------------------------------------------------- | -------- | --------------------------------------------- | ------------------ |
| `pattern` | String pattern used as a template. Every **`x`** will be replaced with a random digit (0–9). | `string` | <i class="fa-square-check">:square-check:</i> | `"xxx-ZAB-x-test"` |

***

### Pattern Behavior

Each occurrence of the character **`x`** in the pattern is replaced with a **random digit from 0 to 9**.\
All other characters are left untouched.

#### Example:

```js
this.generateRandomID("xxx-ZAB-x-test")
// → "053-ZAB-2-test"
```

***

### Example Usage

```js
async function() {
    let x = this.generateRandomID("xxx-ZAB-x-test");  // e.g., "742-ZAB-3-test"
    return x;
}
```

***

### Use Cases

* Generate random **client or user IDs**
* Add randomness to keys or query strings
* Build unique tracking identifiers with a consistent format
* Provide fallback IDs in case external identifiers are missing

***

### Notes

* The number of `x` characters determines how many digits will be included.
* This function generates **non-cryptographic** random numbers (suitable for tracking and general identification).
* To persist generated IDs, consider storing them with `userStorage.write()` or `toolInstanceStorage.write()`.

***

### Summary

`this.generateRandomID` is a lightweight, pattern-based utility for generating unique random identifiers directly in JENTIS server-side variables. It offers simple but powerful control over formatting while injecting dynamic values into your tracking logic.


---

# 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.jentis.com/developer-guide/variables/server-side-variables/public-function-scope/generaterandomid.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.
