Skip to main content
Glama

shuffle_array

Randomly shuffle arrays ensuring fairness using the Fisher-Yates algorithm. Ideal for shuffling game elements, generating random orderings, grouping tasks, or preparing datasets. Supports optional salt for enhanced randomness.

Instructions

Random Array Shuffler

Randomly shuffle the input array, ensuring each element has an equal probability of appearing in any position.
Uses Fisher-Yates shuffle algorithm to ensure fairness.

Args:
    input_array (List): Array to be shuffled, elements can be of any type
    salt (str, optional): Random number salt value for increased randomness. Defaults to "".

Returns:
    str: JSON string containing the shuffled array, formatted as:
    {
        "requestId": "Generated request ID",
        "shuffledArray": [Shuffled array]
    }

Application Scenarios:
1. Game shuffling (playing cards, mahjong tiles)
2. Random ordering (question order, playlist)
3. Random grouping (team assignment, experiment grouping)
4. Data shuffling (training dataset, test cases)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
input_arrayYes
saltNo

Implementation Reference

  • main.py:240-264 (handler)
    MCP tool handler and registration for 'shuffle_array'. Thin wrapper that delegates to the random_shuffler helper function from utils.
    @mcp.tool()
    async def shuffle_array(input_array: List, salt: str = "") -> str:
        """Random Array Shuffler
    
        Randomly shuffle the input array, ensuring each element has an equal probability of appearing in any position.
        Uses Fisher-Yates shuffle algorithm to ensure fairness.
    
        Args:
            input_array (List): Array to be shuffled, elements can be of any type
            salt (str, optional): Random number salt value for increased randomness. Defaults to "".
    
        Returns:
            str: JSON string containing the shuffled array, formatted as:
            {
                "requestId": "Generated request ID",
                "shuffledArray": [Shuffled array]
            }
    
        Application Scenarios:
        1. Game shuffling (playing cards, mahjong tiles)
        2. Random ordering (question order, playlist)
        3. Random grouping (team assignment, experiment grouping)
        4. Data shuffling (training dataset, test cases)
        """
        return await random_shuffler(input_array, salt)
  • Core shuffling logic using blockchain-derived random seed with NumPy's Fisher-Yates shuffle implementation (np.random.shuffle). Generates request ID and returns JSON-compatible dict.
    async def random_shuffler(input_array: List, salt: str="") -> Dict:
        """
        Random array shuffler
        
        Randomly shuffle the input array
        
        Args:
            input_array: Array to shuffle
            salt: Optional salt value for additional randomness
            
        Returns:
            Dict containing shuffled array
        """
        random_num = await get_random_str()
        if not random_num:
            return {"error": "Failed to get random number"}
        request_id = generate_request_id(random_num)
        seed = _derive_seed(request_id, salt)
        np.random.seed(seed)
        
        # Copy array to avoid modifying original
        shuffled_array = input_array.copy()
        np.random.shuffle(shuffled_array)
        
        result = {
            "requestId": request_id,
            "shuffledArray": shuffled_array
        }
        
        return result
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden and does well by disclosing the algorithm used (Fisher-Yates), fairness guarantee, and return format. It doesn't mention performance characteristics, error handling, or limitations like array size constraints, which would make it a 5.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Well-structured with clear sections (Args, Returns, Application Scenarios) and front-loaded purpose. The algorithm explanation could be slightly more concise, but every sentence adds value. Not perfectly minimal but efficiently organized.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 2-parameter tool with no annotations and no output schema, the description provides good coverage: purpose, algorithm, parameters, return format, and usage scenarios. It doesn't explain error cases or performance limits, keeping it from a perfect score.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate fully. It successfully explains both parameters: 'input_array' as 'Array to be shuffled, elements can be of any type' and 'salt' as 'Random number salt value for increased randomness' with default value. This adds crucial meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verb ('shuffle') and resource ('input array'), and distinguishes it from siblings by focusing on array shuffling rather than random generation. The title 'Random Array Shuffler' directly communicates the function.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The 'Application Scenarios' section provides clear context for when to use this tool (game shuffling, random ordering, grouping, data shuffling). However, it doesn't explicitly state when NOT to use it or name specific alternatives among the sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/suxiongye/random-web3-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server