AutoBE
    Preparing search index...

    Random sampler for selecting multiple items from a collection.

    Randomly selects a specified number of elements from a provided collection without duplication. Useful for creating realistic subsets of business data like featured products, selected users, or sample transactions for API operations.

    E2E testing scenarios:

    • Selecting featured products from catalog for API parameters
    • Choosing random users for notification API calls
    • Sampling transactions for analysis operations
    • Creating test data subsets for bulk API operations

    Usage with APIs: Often combined with IApiOperateStatement to perform operations on multiple randomly selected entities.

    AI function calling context: Use when business scenarios require multiple selections from a larger set without duplication, particularly for API operations that handle multiple entities.

    interface ISampleRandom {
        array: IExpression;
        count: IExpression;
        type: "sampleRandom";
    }
    Index

    Properties

    Properties

    Array expression containing the collection to sample from.

    Must be an expression that evaluates to an array containing more elements than the requested sample count to enable meaningful random selection. Elements should be valid business entities appropriate for the sampling context.

    Can reference captured data from previous API operations, array literals, or other expressions that produce collections suitable for sampling.

    Examples:

    • Array of product IDs from captured API response
    • Collection of user entities from previous API call
    • Available options from business configuration
    • Variable references to previously constructed arrays

    The collection size should exceed the count parameter to ensure meaningful random sampling without duplication.

    Business context: Typically represents pools of available entities like product catalogs, user lists, or option sets that need subset selection for API operations.

    Expression determining how many elements to select from the collection.

    Must be an expression that evaluates to a number representing the desired sample size. Should be less than or equal to the collection size to avoid sampling errors. Should represent realistic business requirements for the sampling scenario.

    ⚠️ CRITICAL AI RESTRICTION: This MUST be an AST expression, NOT a raw number! ⚠️

    ❌ WRONG: 3 (raw number) ✅ CORRECT: INumericLiteral with value: 3 (AST expression) ✅ CORRECT: IIntegerRandom for variable count (AST expression)

    Examples:

    • INumericLiteral(3) for exactly 3 featured products
    • IIntegerRandom({ minimum: 2, maximum: 5 }) for variable selection
    • IIdentifier("sampleSize") for dynamic count from captured data

    Business considerations:

    • 3-5 for featured products (typical homepage display)
    • 5-10 for sample users (reasonable notification batch)
    • 10-20 for transaction samples (meaningful analysis size)
    • 2-8 for recommended items (typical recommendation count)

    The count should be appropriate for the business context and not exceed the available collection size. Consider both user experience and system performance when selecting sample sizes for API operations.

    AI selection strategy: Choose counts that reflect realistic business requirements and typical usage patterns, especially when the sampled data will be used in subsequent API operations.

    type: "sampleRandom"

    Type discriminator.