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.) """

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