random_shuffle
Randomize the order of items in a list by returning a new shuffled list.
Instructions
Return a new list with items in random order.
Args: items: List of items to shuffle
Returns: New list with items in random order
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| items | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/random_number_mcp/tools.py:83-98 (handler)Core handler logic for random_shuffle. Validates the list is not empty, then uses random.sample() to return a new shuffled list (instead of shuffling in place).
def random_shuffle(items: list[Any]) -> list[Any]: """Return a new list with items in random order. Args: items: List of items to shuffle Returns: New list with items in random order Raises: ValueError: If items list is empty """ validate_list_not_empty(items, "items") # Use random.sample to return a new list instead of shuffling in place return random.sample(items, len(items)) - src/random_number_mcp/server.py:68-80 (handler)MCP server handler for random_shuffle. Decorated with @app.tool(), it delegates to tools.random_shuffle. Provides type hints restricting items to str | int | float | bool.
@app.tool() def random_shuffle( items: list[str | int | float | bool], ) -> list[str | int | float | bool]: """Return a new list with items in random order. Args: items: List of items to shuffle Returns: New list with items in random order """ return tools.random_shuffle(items) - src/random_number_mcp/server.py:68-80 (registration)Tool registration via @app.tool() decorator on the random_shuffle function in the FastMCP server.
@app.tool() def random_shuffle( items: list[str | int | float | bool], ) -> list[str | int | float | bool]: """Return a new list with items in random order. Args: items: List of items to shuffle Returns: New list with items in random order """ return tools.random_shuffle(items) - src/random_number_mcp/tools.py:7-12 (helper)The validate_list_not_empty helper is used by random_shuffle to ensure the input list is not empty.
from .utils import ( validate_list_not_empty, validate_positive_int, validate_range, validate_weights_match_population, ) - Input schema: items as list[str | int | float | bool]. Output schema: same list type.
items: list[str | int | float | bool], ) -> list[str | int | float | bool]: