random_shuffle
Shuffle any list of items into a new random order using this tool, ideal for generating randomized sequences efficiently. Part of the Random Number MCP server for random generation tasks.
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
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| items | Yes |
Implementation Reference
- src/random_number_mcp/server.py:69-79 (handler)MCP handler function for the 'random_shuffle' tool. Decorated with @app.tool() for registration and delegates execution to the core logic in tools.py.@app.tool() 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 """ return tools.random_shuffle(items)
- src/random_number_mcp/tools.py:83-98 (helper)Core helper function implementing the shuffling logic using random.sample(population, len(population)) to return a new shuffled list without modifying the original.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:69-79 (registration)Registration of the 'random_shuffle' tool via @app.tool() decorator on the FastMCP server instance.@app.tool() 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 """ return tools.random_shuffle(items)