generate_basic_random
Generate a random integer within a specified range for applications like lottery systems, game randomness, ID generation, or test data creation. Customize with optional salt, minimum, and maximum values.
Instructions
Basic Random Number Generator
Generate a random integer within the specified range
Args:
salt (str, optional): Random number salt value for increased randomness. Defaults to "".
min_value (int, optional): Minimum value (inclusive). Defaults to 0.
max_value (int, optional): Maximum value (inclusive). Defaults to 1000000.
Returns:
str: JSON string containing the random number result
Application Scenarios:
1. Lottery systems
2. Game random numbers
3. Random ID generation
4. Test data generation
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "generate_basic_random"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| max_value | No | ||
| min_value | No | ||
| salt | No |
Implementation Reference
- main.py:45-66 (handler)The @mcp.tool()-decorated handler function that defines the tool interface, schema via type hints and docstring, registers the tool, and delegates to the core helper implementation.
@mcp.tool() async def generate_basic_random(salt: str = "", min_value: int = 0, max_value: int = 1000000) -> str: """Basic Random Number Generator Generate a random integer within the specified range Args: salt (str, optional): Random number salt value for increased randomness. Defaults to "". min_value (int, optional): Minimum value (inclusive). Defaults to 0. max_value (int, optional): Maximum value (inclusive). Defaults to 1000000. Returns: str: JSON string containing the random number result Application Scenarios: 1. Lottery systems 2. Game random numbers 3. Random ID generation 4. Test data generation """ return await basic_random_generator(min_value=min_value, max_value=max_value, salt=salt) - utils.py:207-235 (helper)Core helper function containing the exact random number generation logic: fetches blockchain entropy via get_random_str(), derives deterministic seed, seeds numpy RNG, generates value in range, returns structured result.
async def basic_random_generator(min_value: int = 0, max_value: int = 1000000, salt: str="") -> dict: """Basic random number generator""" print(f"\nStarting to generate random number, parameters: salt={salt}, min={min_value}, max={max_value}") try: random_num = await get_random_str() if not random_num: print("Failed to get random number") return {"error": "Failed to get random number"} request_id = generate_request_id(random_num) print(f"Generated request ID: {request_id}") seed = _derive_seed(request_id, salt) print(f"Derived seed: {seed}") np.random.seed(seed) random_value = int(np.random.randint(min_value, max_value + 1)) print(f"Generated random value: {random_value}") result = { "requestId": request_id, "randomValue": random_value } print(f"Final result: {result}") return result except Exception as e: print(f"Failed to generate random number: {str(e)}") return {"error": f"Failed to generate random number: {str(e)}"}