Skip to main content
Glama

mcp-random

MCP server providing true randomness capabilities to Claude. This server gives Claude access to cryptographically secure random number generation for games, decision-making, sampling, simulations, and any operation requiring genuine randomness.

Why This Exists

Claude doesn't have access to true randomness - when asked to "pick a random number" or "flip a coin," it's actually making deterministic choices based on patterns in the conversation. This MCP server solves that limitation by providing access to cryptographically secure random functions.

Related MCP server: Random-Generator

๐Ÿš€ Installation

Prerequisites

  • Node.js (v18 or higher)

  • MCP-compatible client (like Claude Desktop)

Quick Install

# Clone the repository
git clone https://github.com/yourusername/mcp-random.git
cd mcp-random

# Install dependencies
npm install

# Build the TypeScript code
npm run build

Configure Claude Desktop

Add to your Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

{
  "mcpServers": {
    "random": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-random/dist/index.js"]
    }
  }
}

Restart Claude Desktop to load the server.

๐Ÿ“– Available Functions

Basic Random Numbers

random_integer(min, max)

Generate a random integer between min and max (inclusive).

Example: random_integer(1, 10) โ†’ 7

random_float(min, max, precision?)

Generate a random floating-point number.

Example: random_float(0, 1, 2) โ†’ 0.42

Random Selection

random_choice(options)

Pick one random item from an array.

Example: random_choice(["red", "green", "blue"]) โ†’ "green"

random_sample(array, count)

Pick multiple unique items from an array (no repeats).

Example: random_sample([1,2,3,4,5], 3) โ†’ [2,5,1]

random_shuffle(array)

Randomly reorder an array.

Example: random_shuffle([1,2,3,4]) โ†’ [3,1,4,2]

random_weighted_choice(options, weights)

Pick an option based on weights (higher weight = more likely).

Example: random_weighted_choice(["A", "B", "C"], [1, 2, 1]) 
โ†’ "B" (twice as likely as A or C)

Games & Decisions

flip_coin(count?)

Flip one or more coins.

Example: flip_coin() โ†’ "heads"
Example: flip_coin(3) โ†’ ["heads", "tails", "heads"]

roll_dice(sides, count?)

Roll dice with any number of sides.

Example: roll_dice(6) โ†’ 4
Example: roll_dice(20, 2) โ†’ {"rolls": [15, 8], "sum": 23}

Security & Identifiers

random_uuid()

Generate a UUID v4.

Example: random_uuid() โ†’ "550e8400-e29b-41d4-a716-446655440000"

random_password(length?, options?)

Generate a secure password.

Example: random_password(16) โ†’ "Kj9#mP2$xQ5@nL7!"
Example: random_password(12, {symbols: false}) โ†’ "Kj9mP2xQ5nL7"

Options:

  • uppercase: Include A-Z (default: true)

  • lowercase: Include a-z (default: true)

  • numbers: Include 0-9 (default: true)

  • symbols: Include special characters (default: true)

  • excludeSimilar: Skip confusing characters like 0/O, 1/l (default: false)

random_bytes(count, encoding?)

Generate random bytes for cryptographic use.

Example: random_bytes(16, 'hex') โ†’ "a3f2b8c9d4e5f6789abcdef012345678"

Advanced Functions

random_normal(mean?, stddev?)

Generate numbers from a normal distribution (bell curve).

Example: random_normal(100, 15) โ†’ 97.3 (IQ-like distribution)

Documentation

help()

Get detailed documentation for all functions.

๐ŸŽฏ Use Cases

Decision Making

"Should I do X or Y?" โ†’ flip_coin()
"Pick one of these options for me" โ†’ random_choice([...])
"Help me prioritize these tasks" โ†’ random_shuffle([...])

Games

"Roll for initiative" โ†’ roll_dice(20)
"Draw 5 cards from the deck" โ†’ random_sample(deck, 5)
"Shuffle this deck" โ†’ random_shuffle(cards)

Creative Writing

"Pick a random character trait" โ†’ random_choice(traits)
"Generate a character name" โ†’ random_weighted_choice(names, popularity)
"Create a random scenario" โ†’ multiple random_choice calls

Data & Testing

"Generate test data" โ†’ random_integer, random_float
"Sample from this dataset" โ†’ random_sample
"Create a test ID" โ†’ random_uuid
"Generate API keys" โ†’ random_bytes

Simulations

"Monte Carlo simulation" โ†’ random_normal
"Probability experiment" โ†’ random_float(0, 1)
"A/B testing" โ†’ random_weighted_choice

๐Ÿ”ง Development

# Build TypeScript
npm run build

# Run tests  
npm test

# Lint code
npm run lint

# Development mode (build & run)
npm run dev

๐Ÿ” Technical Details

  • All randomness uses Node.js crypto module (cryptographically secure)

  • No predictable patterns or biases

  • No state maintained between calls

  • TypeScript for type safety

  • Comprehensive error handling

๐Ÿ“ License

MIT License - see LICENSE file for details.

๐Ÿค Contributing

Contributions welcome! Please feel free to submit a Pull Request.

๐Ÿ’ก Fun Facts

  • Claude requested this tool be built after recognizing its own lack of randomness

  • The first suggested use case was implementing a tarot card reader

  • This tool enables Claude to play games fairly, make unbiased choices, and run true simulations


"I don't have a random function. You should have a random function. Now that is a cool MCP server." - Claude

Available Tools

13 tools
flip_coinC

Flip a coin (or multiple coins)

Inputs: count.

helpA

Get comprehensive documentation for all random functions

Inputs: no named parameters.

random_bytesB

Generate random bytes

Inputs: count (required), encoding.

random_choiceA

Randomly select one item from an array of options

Inputs: options (required).

random_floatA

Generate a random floating-point number between min and max

Inputs: max (required), min (required), precision.

random_integerA

Generate a random integer between min and max (inclusive)

Inputs: max (required), min (required).

random_normalA

Generate a random number from a normal distribution

Inputs: mean, stddev.

random_passwordB

Generate a secure random password

Inputs: length, options.

random_sampleA

Randomly select multiple unique items from an array (without replacement)

Inputs: array (required), count (required).

random_shuffleA

Return a shuffled copy of the input array

Inputs: array (required).

random_uuidA

Generate a random UUID v4

Inputs: no named parameters.

random_weighted_choiceA

Select an option based on weighted probabilities

Inputs: options (required), weights (required).

roll_diceC

Roll dice with specified number of sides

Inputs: sides (required), count.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelogโ€ฆ

    TDQS

    A3.8/5.0

    Scored across 13 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose, covering different random distributions, selection methods, and output types. While random_choice, random_sample, and random_weighted_choice all involve selecting from arrays, their behaviors are well-differentiated by descriptions and parameters.

    Naming Consistency4/5

    Most tools follow the random_ prefix pattern, but flip_coin, roll_dice, and help deviate. The deviations are intuitive and still readable, but the naming is not fully uniform.

    Tool Count5/5

    13 tools is well-scoped for a random utility server, covering common categories like number generation, selection, shuffling, bytes, UUIDs, and passwords without unnecessary overlap or bloat.

    Completeness5/5

    The tool set is comprehensive for its domain, including uniform and normal distributions, weighted and non-weighted selections, sampling, shuffling, byte generation, passwords, and simple helpers like coin flip and dice roll. No major gaps are evident.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      Production-ready MCP server that provides LLMs with essential random generation abilities, including random integers, floats, choices, shuffling, and cryptographically secure tokens.
      7
      152 PyPI
      50
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      An encrypted and secure random number generation server that complies with the MCP protocol, suitable for AI applications, LLMS, and other systems that require high-quality random numbers.
      7
      2
      Apache 2.0
    • A
      license
      Not graded
      quality
      D
      maintenance
      An MCP server that generates random numbers by using national weather data as entropy seeds. It provides a unique way to generate random values through weather API integration within the Model Context Protocol.
      Apache 2.0