Skip to main content
Glama

generate_random_array

Generate a customizable random array for applications like batch number generation, sampling, test datasets, or task assignments. Specify length, value range, and duplication preferences for tailored results.

Instructions

Random Array Generator

Generate a random array of specified length

Args:
    salt (str, optional): Random number salt value. Defaults to "".
    array_length (int, optional): Array length. Defaults to 1.
    min_value (int, optional): Minimum value. Defaults to 0.
    max_value (int, optional): Maximum value. Defaults to 1000000.
    allow_duplicates (bool, optional): Allow duplicate values. Defaults to True.

Returns:
    str: JSON string containing the random array

Application Scenarios:
1. Batch random number generation
2. Random sampling
3. Test dataset generation
4. Random task assignment

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
allow_duplicatesNo
array_lengthNo
max_valueNo
min_valueNo
saltNo

Implementation Reference

  • main.py:67-90 (handler)
    MCP tool handler and registration for 'generate_random_array'. Includes input schema via type annotations and docstring. Delegates execution to the helper function in utils.py.
    @mcp.tool()
    async def generate_random_array(salt: str = "", array_length: int = 1, min_value: int = 0, 
                                  max_value: int = 1000000, allow_duplicates: bool = True) -> str:
        """Random Array Generator
        
        Generate a random array of specified length
        
        Args:
            salt (str, optional): Random number salt value. Defaults to "".
            array_length (int, optional): Array length. Defaults to 1.
            min_value (int, optional): Minimum value. Defaults to 0.
            max_value (int, optional): Maximum value. Defaults to 1000000.
            allow_duplicates (bool, optional): Allow duplicate values. Defaults to True.
        
        Returns:
            str: JSON string containing the random array
        
        Application Scenarios:
        1. Batch random number generation
        2. Random sampling
        3. Test dataset generation
        4. Random task assignment
        """
        return await random_array_generator(salt, array_length, min_value, max_value, allow_duplicates)
  • Core helper function implementing the random array generation logic using blockchain-derived entropy, seed derivation, and NumPy random functions.
    async def random_array_generator(array_length: int = 1, min_value: int = 0, max_value: int = 1000000, allow_duplicates: bool = True, salt: str="") -> Dict:
        """Random array generator"""
        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)
        
        if allow_duplicates:
            random_array = np.random.randint(min_value, max_value + 1, size=array_length).tolist()
        else:
            # Ensure no duplicates
            if (max_value - min_value + 1) < array_length:
                raise ValueError("Range is too small to generate non-duplicate values")
            
            random_array = np.random.choice(
                range(min_value, max_value + 1), 
                size=array_length, 
                replace=False
            ).tolist()
        
        result = {
            "requestId": request_id,
            "randomArray": random_array
        }
        
        return result
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the return format ('JSON string containing the random array') and the default values for parameters, but doesn't mention important behavioral aspects like whether the generation is deterministic with the salt, performance characteristics, or error conditions for invalid parameter combinations.

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

Conciseness5/5

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

The description is well-structured with clear sections (purpose, Args, Returns, Application Scenarios) and every sentence earns its place. It's appropriately sized for a tool with 5 parameters and provides necessary information without redundancy.

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?

Given the tool's moderate complexity (5 parameters, no output schema, no annotations), the description does a good job covering the essentials: purpose, parameters, return format, and usage scenarios. However, it lacks information about error handling, performance considerations, and the relationship between parameters (like what happens when array_length > (max_value-min_value+1) with allow_duplicates=false).

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

Parameters4/5

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

With 0% schema description coverage, the description must compensate - and it does by documenting all 5 parameters with their types, purposes, and default values in the 'Args' section. This adds significant value beyond the bare schema. However, it doesn't explain the salt's effect on randomness or constraints like min_value <= max_value.

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

Purpose4/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 as 'Generate a random array of specified length' which is a specific verb+resource combination. However, it doesn't explicitly differentiate this tool from sibling tools like 'generate_basic_random' or 'shuffle_array', which prevents a perfect score.

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 (batch generation, sampling, test data, task assignment), giving practical guidance. However, it doesn't explicitly state when NOT to use this tool or mention alternatives among the sibling tools, which would be needed for a score of 5.

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