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
| Name | Required | Description | Default |
|---|---|---|---|
| high | No | ||
| low | No |
Implementation Reference
- src/random_number_mcp/server.py:28-39 (registration)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)
- src/random_number_mcp/tools.py:36-54 (handler)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)
- src/random_number_mcp/utils.py:6-10 (helper)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})")