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

"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:

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

Example Usage

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.

Last updated

Was this helpful?