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): stringParameters
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): Iftrue, embeds the current timestamp (Date.now()). Defaults tofalse.length(number): Length of the random alphanumeric string. Defaults to16.separator(string): The separator string to insert between parts of the ID. Defaults to"".caseOption('upper' | 'lower' | null): Converts the generated ID casing. Defaults tonull.
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)
