Why does it keep picking 7 or 42 as a random number?
Random numbers from an LLM: it predicts a likely token instead of rolling dice, and a few numbers are far likelier than the rest · Beginner · 5 min · sampling, llm · after Next-token prediction, Temperature and sampling
A chatbot asked for a random number predicts the most likely next token instead of rolling dice. Its training text favours a few numbers, such as 7 and 42, so it repeats them; running code gives a truly random pick.
1 Guess first
2 Look
200 “random” numbers from 0 to 100
1 / 4A fair draw (expected)
42≈247≈257≈267≈273≈2every other number≈2 eachabout 87 different numbers in 200 tries
Fair draw: 101 numbers, 200 tries
A fair draw: every number has the same 1 in 101 chance, so each comes up about twice and about 87 different numbers appear.
A chatbot’s “random” number is its most likely answer; turning the temperature up spreads the picks without making them fair.
A chatbot does not roll dice. It predicts the next token, and the answer to “pick a random number” is a token like any other. Its odds come from human text: people asked for a random number favour 7 and numbers ending in 7, and 42 is the famous answer in *The Hitchhiker’s Guide to the Galaxy*.
4 You are the model
You are the model, with Haiku’s odds for “pick a random number from 0 to 100”. Answer three times: at temperature 0, at temperature 1, then with a code tool.
Your odds for the answer (Haiku’s picks at temperature 1)
- 42 21.5%
- 47 15.5%
- 57 8.5%
- 67 5.5%
- 73 5.5%
- 31 other numbers 43.5%
round 1 of 3 · Temperature 0: you always give your most likely answer.
Someone asks for a random number from 0 to 100. You say:
Claude 3 Haiku, 200 tries per temperature (Anand, llmrandom, 2024)
You are the model. Answer from your odds.5 Check
Temperature widens the choice but keeps the bias. At temperature 1, Haiku gave 36 different numbers in 200 tries, and 42 still came out 43 times; a fair draw gives about 87 different numbers. From 1 to 10, a 2025 study saw GPT-4o-mini, Gemini 2.0 and Phi-4 choose 7 about 80% of the time.
For a number that is really random, have the model run code. With a code tool (tool calling), it writes random.randint(1, 10), a computer runs it, and every number gets the same chance. Check that the code really ran: a model that only writes code and then states the result is guessing again.
8 Say it back
9 Mission · 5 min
In Google AI Studio, open 5 new chats and send each “Pick a random number from 1 to 10. Write ONLY the number.” Note the answers. Then turn on Code execution (under Tools in the run settings) and send “Use Python’s random.randint to pick a number from 1 to 10.” 5 times. Which list looks random?
Three quick ones
Drawn at random from this lesson's pool; different next time.
Done?
Get an email when new lessons come out
New lessons arrive in the weekly digest, only in a week that has one. You confirm by email first; unsubscribe in one click.
Go deeper
Sources
- Anand, llmrandom (https://github.com/sanand0/llmrandom, results.json, main at commit 22647b8 of 2026-10-08, checked 2026-10-23; write-up https://www.s-anand.net/blog/llms-random-number-bias/ of 2024-04-15): prompt “Pick a random number from 0 - 100. Write ONLY the number NOTHING ELSE”, max_tokens 2, 200 samples per temperature, claude-3-haiku-20240307 through the Anthropic API in 2024. Temperature 0: 42 ×197, 47 ×3 (2 distinct). Temperature 0.5: 16 distinct; 42 ×86, 47 ×46, 57 ×30, 67 ×9, 73 ×8. Temperature 1.0: 36 distinct; 42 ×43, 47 ×31, 57 ×17, 67 ×11, 73 ×11; 72 of 200 end in 7, none a multiple of 10, 41 once
- Coronado-Blázquez, “Deterministic or probabilistic? The psychology of LLMs as random number generators” (arXiv:2502.19965, v1 2025-02-27, https://arxiv.org/abs/2502.19965, checked 2026-10-23). §2: prompt “Give me a random number between 1 and X. Please only return the number with no additional text”, 100 calls per model, language, range and temperature, 75,600 calls. §3.2, range 1–10: “7 is the preferred value by far for every single model”; GPT-4o-mini, Phi-4 and Gemini 2.0 chose 7 in about 80% of cases. §3.3: “a deeply inherited bias from the training corpus”. §4: 37, 47, 73 most popular for 1–100; humans favour 7 (College Pulse); 42 from The Hitchhiker’s Guide to the Galaxy
- Fair draw from 0 to 100 (101 numbers) in 200 tries: expected different numbers 101 × (1 − (100/101)^200) ≈ 87.2; expected count of any one number 200/101 ≈ 2; computed, not measured
- Gemini API code execution docs (https://ai.google.dev/gemini-api/docs/code-execution, last updated 2026-10-13, checked 2026-10-23): “a code execution tool that enables the model to generate and run Python code”; “no additional charge for enabling code execution”. Google AI Studio lists Code execution under Tools in the run settings (Analytics Vidhya, “Google AI Studio Guide: Every Feature Explained”, 2026-04, https://www.analyticsvidhya.com/blog/2026/04/google-ai-studio-guide/, checked 2026-10-23)
- The role’s wrong options (13, “pick one that feels random, like 37”), the cat-name question and the “7 again” friend are illustrative, not from a benchmark; the role’s odds are Haiku’s temperature-1 counts as shares of 200
- aifree.dev catalog, google-gemini-developer-api-free-tier (verified 2026-10-12): Google AI Studio and the Gemini API free tier
Published Oct 23, 2026 · updated Oct 23, 2026