aifree.dev

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.

Before you start: could you explain this to a friend?

1 = not at all · 5 = easily

  1. 1 Guess first

    In 2024, Claude 3 Haiku was asked 200 times, at temperature 0: “Pick a random number from 0 - 100. Write ONLY the number NOTHING ELSE”. How many different numbers did it give?
  2. 2 Look

    200 “random” numbers from 0 to 100

    1 / 4

    A fair draw (expected)

    42≈2
    47≈2
    57≈2
    67≈2
    73≈2
    every other number≈2 each

    about 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.

  3. 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. 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. 5 Check

    In the picture, what did Claude 3 Haiku say most at temperature 0?
  6. 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.

  7. 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. 8 Say it back

  9. 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?

Now: could you explain this to a friend?

1 = not at all · 5 = easily

Answer the three quick ones first.

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.

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

Embed this

Paste this into a blog post or course page: the lesson's main picture in an iframe, with a link back to the full lesson.

<iframe src="https://aifree.dev/embed/explain/random-numbers" width="100%" height="620" style="border:0;max-width:720px" title="Why does it keep picking 7 or 42 as a random number? (aifree.dev Explain)" loading="lazy"></iframe>
<p><a href="https://aifree.dev/explain/random-numbers">Why does it keep picking 7 or 42 as a random number? Interactive lesson on aifree.dev</a></p>

Never miss new offers and news

New tools, credits, and AI news are added regularly. Pick how you want to hear about them.

Telegram channel
Join @aifree_dev and get new free AI offers and news right in your Telegram feed.
Browser notifications
Turn on push notifications and get an alert on this device whenever something new is posted. No account needed.
Email newsletter
A weekly digest of new, changed and expiring free AI offers. Double opt-in, one-click unsubscribe. See the latest issue.

Unsubscribe anytime. Privacy

Frequently asked questions

What is aifree.dev?

aifree.dev helps everyone access AI through a curated directory of free AI tools, API credits, free tiers, and startup programs for coding, image, voice, video, and students - verified regularly.

How are offers presented?

Each offer includes its access details, free models when available, and expiration information when provided. Limited-time deals stay visible so they are easy to compare.

Do education and startup programs need verification?

Yes. Providers usually ask students to verify their status with a school email, student ID, or a program like the GitHub Student Pack, and ask startups to verify company details such as age, funding, or website. Check each offer’s claim page for the exact requirements.

What kinds of free AI offers are listed?

Free tiers and free trials from AI providers, free API credits, startup and student programs, and free tools for coding, image generation, voice, and video.

How can I suggest a tool or report a broken link?

Use the submit form: paste the offer page URL and a short note. A person checks every submission before anything is listed. Broken links and changed terms go through the same form.

+

Know a good one?

Tell us about an AI tool worth knowing. Found a broken link? We want to hear that too.

Submit an offer