Skip to main content
Glama
zazencodes

Random Number MCP

by zazencodes

random_int

Generate a random integer within a specified range using predefined lower and upper bounds. Ideal for scenarios requiring precise integer randomization in LLM workflows.

Instructions

Generate a random integer between low and high (inclusive).

Args: low: Lower bound (inclusive) high: Upper bound (inclusive)

Returns: Random integer between low and high

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
highYes
lowYes

Implementation Reference

  • FastMCP handler for the 'random_int' tool. Defines the tool schema via type annotations and documentation string. Executes the tool by delegating to the implementation in tools.py.
    @app.tool()
    def random_int(low: int, high: int) -> int:
        """Generate a random integer between low and high (inclusive).
    
        Args:
            low: Lower bound (inclusive)
            high: Upper bound (inclusive)
    
        Returns:
            Random integer between low and high
        """
        return tools.random_int(low, high)
  • Core implementation of the random_int logic, performing input validation and generating the random integer using random.randint.
    def random_int(low: int, high: int) -> int:
        """Generate a random integer between low and high (inclusive).
    
        Args:
            low: Lower bound (inclusive)
            high: Upper bound (inclusive)
    
        Returns:
            Random integer between low and high
    
        Raises:
            ValueError: If low > high
            TypeError: If inputs are not integers
        """
        if not isinstance(low, int) or not isinstance(high, int):
            raise TypeError("Both low and high must be integers")
    
        validate_range(low, high)
        return random.randint(low, high)
  • Utility function used by random_int to validate that the low bound is less than or equal to the high bound.
    def validate_range(low: int | float, high: int | float) -> None:
        """Validate that low <= high for range-based functions."""
        if low > high:
            raise ValueError(f"Low value ({low}) must be <= high value ({high})")
  • The @app.tool() decorator registers 'random_int' as an MCP tool.
    @app.tool()
    def random_int(low: int, high: int) -> int:
        """Generate a random integer between low and high (inclusive).
    
        Args:
            low: Lower bound (inclusive)
            high: Upper bound (inclusive)
    
        Returns:
            Random integer between low and high
        """
        return tools.random_int(low, high)
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