Skip to main content
Glama
VeriTeknik

Pluggedin Random Number Generator

generate_random_choice

Select random items from a list with cryptographically secure randomness. Define the number of choices and allow duplicates for customizable, unbiased results.

Instructions

Randomly select items from a given list using cryptographically secure randomness

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
allow_duplicatesNoWhether to allow duplicate selections
choicesYesArray of items to choose from
countNoNumber of items to select

Implementation Reference

  • The primary handler function that executes the generate_random_choice tool logic. It validates input parameters, generates random selections from the choices array using cryptographically secure randomInt, supports optional duplicates, and returns a standardized JSON response.
    private async generateRandomChoice(args: any) {
      const choices = args.choices;
      const count = args.count ?? 1;
      const allowDuplicates = args.allow_duplicates ?? true;
    
      if (!Array.isArray(choices) || choices.length === 0) {
        throw new Error("Choices must be a non-empty array");
      }
    
      if (count < 1) {
        throw new Error("Count must be at least 1");
      }
    
      if (!allowDuplicates && count > choices.length) {
        throw new Error("Count cannot exceed choices length when duplicates are not allowed");
      }
    
      const results: string[] = [];
      const availableChoices = [...choices];
    
      for (let i = 0; i < count; i++) {
        const randomIndex = randomInt(0, availableChoices.length);
        const selected = availableChoices[randomIndex];
        results.push(selected);
    
        if (!allowDuplicates) {
          availableChoices.splice(randomIndex, 1);
        }
      }
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify({
              type: "random_choices",
              values: results,
              parameters: { choices, count, allow_duplicates: allowDuplicates },
              timestamp: new Date().toISOString(),
            }, null, 2),
          },
        ],
      };
    }
  • Input schema and metadata definition for the generate_random_choice tool, used for validation and documentation in the tools list.
      name: "generate_random_choice",
      description: "Randomly select items from a given list using cryptographically secure randomness",
      inputSchema: {
        type: "object",
        properties: {
          choices: {
            type: "array",
            description: "Array of items to choose from",
            items: {
              type: "string",
            },
            minItems: 1,
          },
          count: {
            type: "integer",
            description: "Number of items to select",
            default: 1,
            minimum: 1,
          },
          allow_duplicates: {
            type: "boolean",
            description: "Whether to allow duplicate selections",
            default: true,
          },
        },
        required: ["choices"],
      },
    },
  • src/index.ts:259-260 (registration)
    Registration in the tool dispatch switch statement within the CallToolRequestSchema handler, routing calls to the handler method.
    case "generate_random_choice":
      return await this.generateRandomChoice(args);
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/VeriTeknik/pluggedin-random-number-generator-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server