Random Number MCP Server — Built on the Python Standard Library

Introducing the Random Number MCP server. Built on the Python standard library with pseudorandom functions for "everyday" randomness and cryptographically secure methods for generating hex tokens and integers. ## What it is Random Number MCP is a Model Context Protocol server that provides genuine randomness to LLMs through the use of tools. ### Try it out > Full setup and usage instructions can be found [in the docs on GitHub](https://github.com/zazencodes/random-number-mcp/tree/main?tab=readme-ov-file#-setup). 1. **Configure your LLM client to use `random-number-mcp`**: ```json { "mcpServers": { "random-number": { "command": "uvx", "args": ["random-number-mcp"] } } } ``` 2. **Ask a question that needs randomness**: - roll a d20 - give me a random pastel color in HSV - generate a new user id - what should I listen to? jazz, lo-fi or j-pop? (weight j-pop at 70%) - split these people up into 2 teams: rick, morty, summer, jerry, beth, evil morty - a secure random number between 1 - 50 <iframe width="800" height="450" src="https://www.youtube.com/embed/SMQd--Q2DPI" frameborder="0" allowfullscreen></iframe> ### The toolbox | Tool | Returns | Backed by | | ------------------- | ---------------------------- | ------------------- | | `random_int` | uniform int between bounds | `random.randint` | | `random_float` | float between bounds | `random.uniform` | | `random_choices` | weighted or unweighted picks | `random.choices` | | `random_shuffle` | shuffled copy of a list | `random.sample` | | `random_sample` | Choose k unique items from population | `random.sample` | | `secure_token_hex` | cryptographically safe hex | `secrets.token_hex` | | `secure_random_int` | secure int < N | `secrets.randbelow` | ## Why you need it ### The "27 club" effect Ask ChatGPT, Claude, Perplexity, Meta AI and Gemini for "a random number between 1 - 50" and they all guess 27. Or at least, that's what [Andrej Karpathy called out on X](https://x.com/karpathy/status/1935404600653492484). As he described it: "not 100% reproducible but still quite reproducible". ### The Randomness and Humaness of LLMs' Coin Flips The inability for LLMs to generate truly random data has also been studied more rigorously. Researchers at Cornell [tested the ability for ChatGPT and Llama to flip a coin](https://arxiv.org/abs/2406.00092), and found the LLMs replicating (and exacerbating) human biases. i.e. They were unable to generate true randomness. The researchers pointed out: > One uniquely human trait is our inability to be random. We see and produce patterns where there should not be any and we do so in a predictable way. LLMs are supplied with human data and prone to human biases. ## Source code #### `random-number-mcp` - GitHub & PyPI https://github.com/zazencodes/random-number-mcp > Please give this project a star on GitHub if you find it useful. > > Pull requests and issues are encouraged. ## Security notes * **Simulation tools** (`random_*`) are not cryptographically safe, but perfect for dice rolls, simulation data, etc. * **Secure tools** (`secure_*`) have stronger random numbers, with potential applications for API tokens, password generators, etc. | Module | Documentation Link | |---------|----------------------------------------------------------| | `random` | [Python Docs](https://docs.python.org/3/library/random.html) | | `secrets` | [Python Docs](https://docs.python.org/3/library/secrets.html) | ## Getting involved I encourage you to [browse the source code](https://github.com/zazencodes/random-number-mcp/blob/main/src/random_number_mcp/tools.py) and star, fork or open an issue on GitHub --- contributions are welcome!
Introducing the Random Number MCP server. Built on the Python standard library with pseudorandom functions for “everyday” randomness and cryptographically secure methods for generating hex tokens and integers.
What it is
Random Number MCP is a Model Context Protocol server that provides genuine randomness to LLMs through the use of tools.
Try it out
Full setup and usage instructions can be found in the docs on GitHub.
-
Configure your LLM client to use
random-number-mcp:{ "mcpServers": { "random-number": { "command": "uvx", "args": ["random-number-mcp"] } } } -
Ask a question that needs randomness:
- roll a d20
- give me a random pastel color in HSV
- generate a new user id
- what should I listen to? jazz, lo-fi or j-pop? (weight j-pop at 70%)
- split these people up into 2 teams: rick, morty, summer, jerry, beth, evil morty
- a secure random number between 1 - 50
The toolbox
| Tool | Returns | Backed by |
|---|---|---|
random_int |
uniform int between bounds | random.randint |
random_float |
float between bounds | random.uniform |
random_choices |
weighted or unweighted picks | random.choices |
random_shuffle |
shuffled copy of a list | random.sample |
random_sample |
Choose k unique items from population | random.sample |
secure_token_hex |
cryptographically safe hex | secrets.token_hex |
secure_random_int |
secure int < N | secrets.randbelow |
Why you need it
The “27 club” effect
Ask ChatGPT, Claude, Perplexity, Meta AI and Gemini for “a random number between 1 - 50” and they all guess 27.
Or at least, that’s what Andrej Karpathy called out on X.
As he described it: “not 100% reproducible but still quite reproducible”.
The Randomness and Humaness of LLMs’ Coin Flips
The inability for LLMs to generate truly random data has also been studied more rigorously.
Researchers at Cornell tested the ability for ChatGPT and Llama to flip a coin, and found the LLMs replicating (and exacerbating) human biases.
i.e. They were unable to generate true randomness.
The researchers pointed out:
One uniquely human trait is our inability to be random. We see and produce patterns where there should not be any and we do so in a predictable way. LLMs are supplied with human data and prone to human biases.
Source code
random-number-mcp - GitHub & PyPI
https://github.com/zazencodes/random-number-mcp
Please give this project a star on GitHub if you find it useful.
Pull requests and issues are encouraged.
Security notes
- Simulation tools (
random_*) are not cryptographically safe, but perfect for dice rolls, simulation data, etc. - Secure tools (
secure_*) have stronger random numbers, with potential applications for API tokens, password generators, etc.
| Module | Documentation Link |
|---|---|
random |
Python Docs |
secrets |
Python Docs |
Getting involved
I encourage you to browse the source code and star, fork or open an issue on GitHub — contributions are welcome!
ZazenCodes
Agentic Coding Club
- Weekly LIVE build sessions — 30 min building, 30 min Q&A
- Free to join, full course library with Premium

Comments (0)
No comments yet.