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
| Name | Required | Description | Default |
|---|---|---|---|
| high | Yes | ||
| low | Yes |
Implementation Reference
- src/random_number_mcp/server.py:14-26 (handler)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)
- src/random_number_mcp/tools.py:15-33 (handler)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)
- src/random_number_mcp/utils.py:6-10 (helper)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})")
- src/random_number_mcp/server.py:14-26 (registration)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)