generate_random_boolean
Generate cryptographically secure random boolean values with customizable counts and probability settings. Ideal for simulations, testing, and decision-making applications.
Instructions
Generate cryptographically secure random boolean values
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | No | Number of random booleans to generate | |
| probability | No | Probability of true (0.0 to 1.0) |
Implementation Reference
- src/index.ts:594-626 (handler)The core handler function implementing the generate_random_boolean tool. It generates an array of random booleans using Node.js crypto.randomBytes for cryptographic security, respecting count and probability parameters, and returns a structured JSON response.private async generateRandomBoolean(args: any) { const count = args.count ?? 1; const probability = args.probability ?? 0.5; if (count < 1 || count > 1000) { throw new Error("Count must be between 1 and 1000"); } if (probability < 0.0 || probability > 1.0) { throw new Error("Probability must be between 0.0 and 1.0"); } const results: boolean[] = []; for (let i = 0; i < count; i++) { const randomBuffer = randomBytes(4); const randomValue = randomBuffer.readUInt32BE(0) / 0xFFFFFFFF; results.push(randomValue < probability); } return { content: [ { type: "text", text: JSON.stringify({ type: "random_booleans", values: results, parameters: { count, probability }, timestamp: new Date().toISOString(), }, null, 2), }, ], }; }
- src/index.ts:218-237 (schema)Input schema definition for the generate_random_boolean tool, specifying parameters for count (1-1000) and probability (0.0-1.0) with defaults.inputSchema: { type: "object", properties: { count: { type: "integer", description: "Number of random booleans to generate", default: 1, minimum: 1, maximum: 1000, }, probability: { type: "number", description: "Probability of true (0.0 to 1.0)", default: 0.5, minimum: 0.0, maximum: 1.0, }, }, required: [], },
- src/index.ts:215-238 (registration)Tool registration in the ListToolsRequestSchema handler, defining name, description, and input schema for generate_random_boolean.{ name: "generate_random_boolean", description: "Generate cryptographically secure random boolean values", inputSchema: { type: "object", properties: { count: { type: "integer", description: "Number of random booleans to generate", default: 1, minimum: 1, maximum: 1000, }, probability: { type: "number", description: "Probability of true (0.0 to 1.0)", default: 0.5, minimum: 0.0, maximum: 1.0, }, }, required: [], }, },
- src/index.ts:261-262 (registration)Dispatch registration in the CallToolRequestSchema switch statement, routing calls to generate_random_boolean to the handler method.case "generate_random_boolean": return await this.generateRandomBoolean(args);