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

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)

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