Skip to main content
Glama
zazencodes

Random Number MCP

by zazencodes

random_float

Generate custom floating-point numbers within a specified range using this tool. Set lower and upper bounds to create precise random values for simulations, testing, or data modeling.

Instructions

Generate a random float between low and high.

Args: low: Lower bound (default 0.0) high: Upper bound (default 1.0)

Returns: Random float between low and high

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
highNo
lowNo

Implementation Reference

  • Registration of the 'random_float' MCP tool using the @app.tool() decorator, which also defines the input schema via type hints and docstring.
    @app.tool()
    def random_float(low: float = 0.0, high: float = 1.0) -> float:
        """Generate a random float between low and high.
    
        Args:
            low: Lower bound (default 0.0)
            high: Upper bound (default 1.0)
    
        Returns:
            Random float between low and high
        """
        return tools.random_float(low, high)
  • Core handler implementation for generating random float using random.uniform after validation.
    def random_float(low: float = 0.0, high: float = 1.0) -> float:
        """Generate a random float between low and high.
    
        Args:
            low: Lower bound (default 0.0)
            high: Upper bound (default 1.0)
    
        Returns:
            Random float between low and high
    
        Raises:
            ValueError: If low > high
            TypeError: If inputs are not numeric
        """
        if not isinstance(low, int | float) or not isinstance(high, int | float):
            raise TypeError("Both low and high must be numeric")
    
        validate_range(low, high)
        return random.uniform(low, high)
  • Helper function validate_range used to ensure low <= high in random_float.
    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})")
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