Toolbox-XToolbox-X

Generate Random ID

Generates a customizable random alphanumeric ID with optional prefixes, suffixes, timestamps, and case formats.

generateRandomID

The generateRandomID function creates a customizable random alphanumeric ID string. It supports custom prefixes, suffixes, separators, case transformations, and embedding current timestamps.

Function Signature

function generateRandomID(options?: RandomIdOptions): string

Parameters

  • options (RandomIdOptions, optional): Configuration options for the ID:
    • prefix (string): A string to prepend to the ID. Defaults to "".
    • suffix (string): A string to append to the ID. Defaults to "".
    • timeStamp (boolean): If true, embeds the current timestamp (Date.now()). Defaults to false.
    • length (number): Length of the random alphanumeric string. Defaults to 16.
    • separator (string): The separator string to insert between parts of the ID. Defaults to "".
    • caseOption ('upper' | 'lower' | null): Converts the generated ID casing. Defaults to null.

Types

RandomIdOptions

interface RandomIdOptions {
  prefix?: string;
  suffix?: string;
  timeStamp?: boolean;
  length?: number;
  separator?: string;
  caseOption?: 'upper' | 'lower' | null;
}

Return Value

  • string: The generated random ID.

Example Usage

playground.ts

See Also

  • randomHex - Generate cryptographically secure random hex strings
  • randomBytes - Generate cryptographically secure random bytes (Uint8Array)
  • randomNumeric - Generate cryptographically secure random numeric strings
  • randomAlphaNumeric - Generate cryptographically secure random alphanumeric strings

Last updated: Tue, Jun 16, 2026 06:17:07PM (UTC)

On this page