random_int
Generate a random integer between two inclusive bounds. Specify a low and high value to receive a random number within that range.
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
| Name | Required | Description | Default |
|---|---|---|---|
| low | Yes | ||
| high | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- tests/test_tools.py:22-50 (schema)Tests for random_int, covering basic usage, same bounds, negative ranges, invalid ranges, and non-integer inputs. Effectively documents the expected input/output contract.
class TestRandomInt: """Tests for random_int function.""" def test_random_int_basic(self): """Test basic random integer generation.""" result = random_int(1, 10) assert isinstance(result, int) assert 1 <= result <= 10 def test_random_int_same_bounds(self): """Test random integer with same low and high.""" result = random_int(5, 5) assert result == 5 def test_random_int_negative_range(self): """Test random integer with negative range.""" result = random_int(-10, -1) assert isinstance(result, int) assert -10 <= result <= -1 def test_random_int_invalid_range(self): """Test random integer with invalid range.""" with pytest.raises(ValueError, match="Low value .* must be <= high value"): random_int(10, 5) def test_random_int_non_integer_input(self): """Test random integer with non-integer input.""" with pytest.raises(TypeError, match="Both low and high must be integers"): random_int(1.5, 10) - examples/demo_host.py:84-90 (helper)Example usage demonstrating how to call random_int via the MCP client.
# Demo random_int print("\n1. random_int - Generate random integers") result = await client.call_tool("random_int", {"low": 1, "high": 100}) print(f" Random integer (1-100): {result}") result = await client.call_tool("random_int", {"low": -10, "high": 10}) print(f" Random integer (-10 to 10): {result}")