Skip to main content
Glama

generate_random_feature

Allocate random feature values within specified ranges for objects, encoded into a bitmap. Use for game attributes, equipment stats, trait simulations, or random scene generation.

Instructions

Random Feature Allocator

Generate a set of random feature values for objects, each feature value within its specified range.
Feature values are encoded into a bitmap, with each feature occupying 8 bits.

Args:
    feature_count (int): Number of features to generate
    feature_max_values (List[int]): List of maximum values for each feature, length must equal feature_count
    salt (str, optional): Random number salt value for increased randomness. Defaults to "".

Returns:
    str: JSON string containing feature values and bitmap, formatted as:
    {
        "requestId": "Generated request ID",
        "features": [List of feature values],
        "featureBitmap": Feature bitmap value
    }

Application Scenarios:
1. Game character attribute generation (strength, agility, intelligence, etc.)
2. Equipment attribute randomization (attack, defense, speed, etc.)
3. Biological trait simulation (genes, traits, etc.)
4. Random scene generation (terrain, weather, environment, etc.)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
feature_countYes
feature_max_valuesYes
saltNo

Implementation Reference

  • main.py:114-141 (handler)
    The primary MCP tool handler decorated with @mcp.tool(), defining input parameters and docstring schema, delegating execution to the helper function.
    @mcp.tool()
    async def generate_random_feature(feature_count: int, feature_max_values: List[int], salt: str = "") -> str:
        """Random Feature Allocator
    
        Generate a set of random feature values for objects, each feature value within its specified range.
        Feature values are encoded into a bitmap, with each feature occupying 8 bits.
    
        Args:
            feature_count (int): Number of features to generate
            feature_max_values (List[int]): List of maximum values for each feature, length must equal feature_count
            salt (str, optional): Random number salt value for increased randomness. Defaults to "".
    
        Returns:
            str: JSON string containing feature values and bitmap, formatted as:
            {
                "requestId": "Generated request ID",
                "features": [List of feature values],
                "featureBitmap": Feature bitmap value
            }
    
        Application Scenarios:
        1. Game character attribute generation (strength, agility, intelligence, etc.)
        2. Equipment attribute randomization (attack, defense, speed, etc.)
        3. Biological trait simulation (genes, traits, etc.)
        4. Random scene generation (terrain, weather, environment, etc.)
        """
        return await random_feature_allocator(feature_count, feature_max_values, salt)
  • Core logic implementing the random feature generation: derives seed from blockchain random source, uses numpy RNG to generate features within ranges, encodes into bitmap.
    async def random_feature_allocator(feature_count: int, feature_max_values: List[int], salt: str="") -> Dict:
        """
        Random feature allocator
        
        Generate random feature values for each feature within specified ranges
        
        Args:
            feature_count: Number of features to generate
            feature_max_values: Maximum value for each feature
            salt: Optional salt value for additional randomness
            
        Returns:
            Dict containing feature values and bitmap
        """
        if len(feature_max_values) != feature_count:
            raise ValueError("Feature count must match length of max values 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)
        
        features = []
        feature_bitmap = 0
        
        for i in range(feature_count):
            max_val = feature_max_values[i]
            feature_val = np.random.randint(0, max_val + 1)
            features.append(int(feature_val))
            
            # Encode feature into bitmap (8 bits per feature)
            feature_bitmap |= (feature_val << (i * 8))
        
        result = {
            "requestId": request_id,
            "features": features,
            "featureBitmap": feature_bitmap
        }
        
        return result
  • main.py:114-114 (registration)
    The @mcp.tool() decorator registers the generate_random_feature function as an MCP tool.
    @mcp.tool()
  • Type hints and comprehensive docstring define the input schema (parameters with types/descriptions) and output format for the tool.
    async def generate_random_feature(feature_count: int, feature_max_values: List[int], salt: str = "") -> str:
        """Random Feature Allocator
    
        Generate a set of random feature values for objects, each feature value within its specified range.
        Feature values are encoded into a bitmap, with each feature occupying 8 bits.
    
        Args:
            feature_count (int): Number of features to generate
            feature_max_values (List[int]): List of maximum values for each feature, length must equal feature_count
            salt (str, optional): Random number salt value for increased randomness. Defaults to "".
    
        Returns:
            str: JSON string containing feature values and bitmap, formatted as:
            {
                "requestId": "Generated request ID",
                "features": [List of feature values],
                "featureBitmap": Feature bitmap value
            }
    
        Application Scenarios:
        1. Game character attribute generation (strength, agility, intelligence, etc.)
        2. Equipment attribute randomization (attack, defense, speed, etc.)
        3. Biological trait simulation (genes, traits, etc.)
        4. Random scene generation (terrain, weather, environment, etc.)
        """
Behavior4/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 effectively describes key behaviors: it generates random values within specified ranges, encodes them into an 8-bit bitmap, and returns a JSON string with specific fields. It also mentions the optional salt parameter for increased randomness. However, it doesn't cover potential limitations like rate limits, error conditions, or performance characteristics.

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?

The description is well-structured with clear sections (purpose, args, returns, application scenarios) and front-loads the core functionality. Most sentences earn their place by providing essential information. However, the 'Application Scenarios' section could be slightly more concise, and the description is somewhat longer than minimal necessary.

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 no annotations and no output schema, the description provides substantial context: clear purpose, parameter semantics, return format, and usage scenarios. It effectively compensates for the lack of structured metadata. The main gap is the absence of explicit error handling or boundary case information, preventing 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?

The schema description coverage is 0%, so the description must fully compensate. It does this excellently by explaining all three parameters: feature_count (number of features), feature_max_values (list of maximum values with length constraint), and salt (optional random number salt with default value). The description adds crucial semantic information beyond the bare schema, including the relationship between feature_count and feature_max_values length.

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: 'Generate a set of random feature values for objects, each feature value within its specified range.' It specifies the verb (generate) and resource (random feature values) with details about encoding into a bitmap. However, it doesn't explicitly differentiate from sibling tools like generate_basic_random or generate_random_array, which may also generate random values.

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 contexts for when to use this tool (e.g., game character attribute generation, equipment attribute randomization). This gives practical guidance on appropriate use cases. However, it doesn't explicitly state when NOT to use it or mention alternatives among sibling tools, which would be needed for a perfect score.

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