@typia/website
    Preparing search index...

    Interface IRandomGenerator

    Interface for generating random values for various data types.

    IRandomGenerator defines the contract for generating random values that can be used by typia for creating mock data, testing scenarios, and random value generation based on JSON schema constraints.

    This interface supports generating random values for:

    • Basic types (boolean, number, integer, bigint, string, array)
    • String format patterns (email, URL, UUID, etc.)
    • Date and time formats
    • Various address and identifier formats

    Jeongho Nam - https://github.com/samchon

      const generator: IRandomGenerator = {
    boolean: () => Math.random() > 0.5,
    number: (schema) => Math.random() * (schema.maximum ?? 100),
    string: (schema) => "example-string",
    email: () => "test@example.com",
    // ... implement other methods
    };
    interface IRandomGenerator {
        array<T>(
            schema: Omit<IArray, "items"> & {
                element: (index: number, count: number) => T;
            },
        ): T[];
        bigint(schema: IInteger): bigint;
        boolean(): undefined | boolean;
        byte(): string;
        date(props?: { maximum?: number; minimum?: number }): string;
        datetime(props?: { maximum?: number; minimum?: number }): string;
        duration(): string;
        email(): string;
        hostname(): string;
        idnEmail(): string;
        idnHostname(): string;
        integer(schema: IInteger): number;
        ipv4(): string;
        ipv6(): string;
        iri(): string;
        iriReference(): string;
        jsonPointer(): string;
        number(schema: INumber): number;
        password(): string;
        pattern(regex: RegExp): string;
        regex(): string;
        relativeJsonPointer(): string;
        string(schema: IString): string;
        time(): string;
        uri(): string;
        uriReference(): string;
        uriTemplate(): string;
        url(): string;
        uuid(): string;
    }
    Index

    Methods

    • Generates a random array with elements created by the provided generator function.

      Type Parameters

      • T

      Parameters

      • schema: Omit<IArray, "items"> & { element: (index: number, count: number) => T }

        Array schema with element generator function

      Returns T[]

      Random array with generated elements

    • Generates a random bigint based on JSON schema constraints.

      Parameters

      • schema: IInteger

        JSON schema with integer constraints (min, max, etc.)

      Returns bigint

      Random bigint within the specified constraints

    • Generates a random boolean value.

      Returns undefined | boolean

      Random boolean value or undefined

    • Generates a random date string in ISO 8601 format (YYYY-MM-DD).

      Parameters

      • Optionalprops: { maximum?: number; minimum?: number }

        Optional constraints for minimum and maximum timestamp values

      Returns string

      Random date string

    • Generates a random datetime string in ISO 8601 format.

      Parameters

      • Optionalprops: { maximum?: number; minimum?: number }

        Optional constraints for minimum and maximum timestamp values

      Returns string

      Random datetime string

    • Generates a random duration string in ISO 8601 format.

      Returns string

      Random duration string

    • Generates a random internationalized email address.

      Returns string

      Random IDN email address

    • Generates a random internationalized hostname.

      Returns string

      Random IDN hostname

    • Generates a random integer based on JSON schema constraints.

      Parameters

      • schema: IInteger

        JSON schema with integer constraints (min, max, etc.)

      Returns number

      Random integer within the specified constraints

    • Generates a random IRI (Internationalized Resource Identifier).

      Returns string

      Random IRI

    • Generates a random number based on JSON schema constraints.

      Parameters

      • schema: INumber

        JSON schema with number constraints (min, max, etc.)

      Returns number

      Random number within the specified constraints

    • Generates a random string matching the given regular expression pattern.

      Parameters

      • regex: RegExp

        Regular expression pattern to match

      Returns string

      Random string matching the pattern

    • Generates a random regular expression pattern string.

      Returns string

      Random regex pattern

    • Generates a random relative JSON pointer string.

      Returns string

      Random relative JSON pointer

    • Generates a random string based on JSON schema constraints.

      Parameters

      • schema: IString

        JSON schema with string constraints (minLength, maxLength, pattern, etc.)

      Returns string

      Random string matching the specified constraints

    • Generates a random time string in ISO 8601 format (HH:MM:SS).

      Returns string

      Random time string

    • Generates a random UUID (Universally Unique Identifier).

      Returns string

      Random UUID string in standard format