Skip to main content
Glama
zazencodes

Random Number MCP

by zazencodes

random_sample

Select k unique elements from a population without replacement using the Random Number MCP server. Ideal for generating unbiased, random subsets efficiently.

Instructions

Choose k unique items from population without replacement.

Args: population: List of items to choose from k: Number of items to choose

Returns: List of k unique chosen items

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kYes
populationYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for 'random_sample' registered via @app.tool() decorator. Delegates execution to the helper in tools.py.
    @app.tool()
    def random_sample(population: list[Any], k: int) -> list[Any]:
        """Choose k unique items from population without replacement.
    
        Args:
            population: List of items to choose from
            k: Number of items to choose
    
        Returns:
            List of k unique chosen items
        """
        return tools.random_sample(population, k)
  • Core helper function implementing random sampling logic using Python's random.sample, including input validation.
    def random_sample(population: list[Any], k: int) -> list[Any]:
        """Choose k unique items from population without replacement.
    
        Args:
            population: List of items to choose from
            k: Number of items to choose
    
        Returns:
            List of k unique chosen items
    
        Raises:
            ValueError: If population is empty, k < 0, or k > len(population)
            TypeError: If k is not an integer
        """
        validate_list_not_empty(population, "population")
        validate_positive_int(k, "k")
        if k > len(population):
            raise ValueError("Sample size k cannot be greater than population size")
        return random.sample(population, k)
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses the key behavioral trait 'without replacement' and specifies uniqueness, but doesn't mention randomness quality, performance characteristics, or error conditions. It adequately describes the core behavior but lacks richer context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Perfectly structured with a clear purpose statement followed by Args and Returns sections. Every sentence earns its place - no wasted words. The information is front-loaded with the core operation first.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity, 2 parameters, no annotations, but with output schema (which handles return values), the description is complete enough. It covers purpose, parameters, returns, and key constraint (without replacement) - everything needed for this straightforward sampling tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description fully compensates by clearly explaining both parameters: 'population: List of items to choose from' and 'k: Number of items to choose'. This adds essential meaning beyond the bare schema types (array and integer).

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific verb ('choose') and resource ('k unique items from population') with the key constraint 'without replacement'. It distinguishes from siblings like random_choices (which likely allows replacement) and random_shuffle (which reorders rather than samples).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for sampling without replacement, but doesn't explicitly state when to use this vs alternatives like random_choices (with replacement) or random_shuffle. It provides clear context about the operation but lacks explicit exclusions or named alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/zazencodes/random-number-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server