Skip to main content
Glama

generate_random_event

Trigger multiple random events with specified probabilities for applications like game mechanics, skill triggers, risk simulations, and combined probability scenarios. Returns detailed JSON results for each event's trigger status and random values.

Instructions

Random Event Trigger

Trigger a series of events based on given probabilities, each event has an independent trigger probability.
Uses bitmap to record trigger status for easy processing.

Args:
    event_count (int): Total number of events
    event_probabilities (List[int]): Trigger probability for each event (0-1000, representing 0-100%)
    salt (str, optional): Random number salt value for increased randomness. Defaults to "".

Returns:
    str: JSON string containing event trigger results, formatted as:
    {
        "requestId": "Generated request ID",
        "triggeredEvents": Event trigger bitmap,
        "eventResults": [
            {
                "eventId": Event ID,
                "probability": Trigger probability,
                "triggered": Whether triggered,
                "randomValue": Random value
            },
            ...
        ]
    }

Application Scenarios:
1. Game random events (trigger plot, drop items)
2. Probability effect determination (skill trigger, combo determination)
3. Risk event simulation (fault prediction, accident events)
4. Multiple condition determination (combined probability events)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
event_countYes
event_probabilitiesYes
saltNo

Implementation Reference

  • main.py:177-211 (handler)
    MCP tool handler for 'generate_random_event' decorated with @mcp.tool(). Delegates to utils.random_event_trigger for core logic.
    @mcp.tool()
    async def generate_random_event(event_count: int, event_probabilities: List[int], salt: str = "") -> str:
        """Random Event Trigger
    
        Trigger a series of events based on given probabilities, each event has an independent trigger probability.
        Uses bitmap to record trigger status for easy processing.
    
        Args:
            event_count (int): Total number of events
            event_probabilities (List[int]): Trigger probability for each event (0-1000, representing 0-100%)
            salt (str, optional): Random number salt value for increased randomness. Defaults to "".
    
        Returns:
            str: JSON string containing event trigger results, formatted as:
            {
                "requestId": "Generated request ID",
                "triggeredEvents": Event trigger bitmap,
                "eventResults": [
                    {
                        "eventId": Event ID,
                        "probability": Trigger probability,
                        "triggered": Whether triggered,
                        "randomValue": Random value
                    },
                    ...
                ]
            }
    
        Application Scenarios:
        1. Game random events (trigger plot, drop items)
        2. Probability effect determination (skill trigger, combo determination)
        3. Risk event simulation (fault prediction, accident events)
        4. Multiple condition determination (combined probability events)
        """
        return await random_event_trigger(event_count, event_probabilities, salt)
  • Core helper function implementing the random event triggering logic using blockchain-derived randomness, numpy seeding, probability checks, and bitmap encoding.
    async def random_event_trigger(event_count: int, event_probabilities: List[int], salt: str="") -> Dict:
        """
        Random event trigger
        
        Trigger events based on their individual probabilities
        
        Args:
            event_count: Number of events
            event_probabilities: Probability for each event (0-1000)
            salt: Optional salt value for additional randomness
            
        Returns:
            Dict containing triggered events and their results
        """
        if len(event_probabilities) != event_count:
            raise ValueError("Event count must match probabilities array length")
        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)
        
        triggered_events = 0
        event_results = []
        
        for i in range(event_count):
            probability = event_probabilities[i]
            if not 0 <= probability <= 1000:
                raise ValueError("Probability must be between 0 and 1000")
            
            # Generate random number between 0-999
            random_value = np.random.randint(0, 1000)
            is_triggered = random_value < probability
            
            event_results.append({
                "eventId": i,
                "probability": probability / 10,  # Convert to percentage
                "triggered": is_triggered,
                "randomValue": int(random_value)
            })
            
            # Encode trigger result into bitmap
            if is_triggered:
                triggered_events |= (1 << i)
        
        result = {
            "requestId": request_id,
            "triggeredEvents": triggered_events,
            "eventResults": event_results
        }
        
        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. It discloses key behavioral traits: it triggers events probabilistically, uses a bitmap for status recording, and returns a JSON string with detailed results. However, it lacks information on side effects, error handling, or performance characteristics like rate limits.

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

Conciseness3/5

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

The description is structured with sections (Args, Returns, Application Scenarios) but is somewhat verbose. Sentences like 'Uses bitmap to record trigger status for easy processing' add value, but the list of scenarios could be more concise. It's front-loaded with the core purpose.

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, no output schema, and 0% schema coverage, the description provides good context: it explains the tool's purpose, parameters, return format, and usage scenarios. However, it doesn't cover error cases or edge behaviors, leaving some gaps for a probabilistic tool with 3 parameters.

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?

Schema description coverage is 0%, so the description must compensate. It adds meaningful semantics: 'event_count' as total number of events, 'event_probabilities' as trigger probabilities (0-1000 for 0-100%), and 'salt' as a random number salt for increased randomness. This clarifies beyond the bare schema, though it could detail format constraints more.

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: 'Trigger a series of events based on given probabilities, each event has an independent trigger probability.' It specifies the verb ('trigger') and resource ('events'), though it doesn't explicitly differentiate from siblings like 'generate_random_weighted' or 'generate_random_array' beyond mentioning 'bitmap' recording.

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 random events, probability effect determination, risk simulation). However, it doesn't explicitly state when not to use it or name alternatives among siblings, such as when simpler random generation might suffice.

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