Skip to main content
Joshua Thompson

AI

Why Do AIs Pick 42 or 17? Random Numbers and Seed 42 Explained

Why AIs pick numbers such as 42 or 17, why random_state=42 appears in code, and why an LLM should not be treated as a random-number generator.

By Joshua Thompson

3 min read

The short answer

The short answer is that LLMs behave as biased text generators rather than uniform random-number generators.

Research into LLM number generation found strong, repeatable preferences rather than genuinely random choices. The preferred answers varied by model, prompt language, temperature and number range. That means an AI may favour 42 or 17 without either number being a universal AI default.

Why do AIs pick 42?

Douglas Adams made 42 famous as the answer to the Ultimate Question of Life, the Universe, and Everything.

Because 42 is culturally established as Adams's famous answer and the LLM study identifies it as a culturally salient exception, the number is more likely to appear than a uniform draw would suggest.

It is not a hidden preference or a mystical property of the model. It is a familiar pattern from human culture being reproduced in generated text.

Why do AIs sometimes pick 17 instead?

There is no single number that AIs always choose. The evidence shows that number preferences depend on the model, language, prompt, temperature and available range.

The same research found preferences for central values in small ranges and for numbers such as 37, 47 and 73 in larger ranges. It also connects these choices with human habits such as avoiding extremes and numbers that look too neat.

So 17 may appear frequently in a particular experiment, but the evidence does not establish it as the universal AI number.

Why LLM randomness is not uniform randomness

An LLM generates a response by selecting likely next tokens. It does not automatically perform a uniform draw from every valid integer in the range you specified.

Changing the temperature can change which numbers appear, but the observed preferences still vary with the model, language and range. More varied output is not the same thing as statistically uniform output.

This is why a prompt such as "pick a random number" can repeatedly produce familiar, human-looking answers. The model is imitating patterns associated with randomness rather than proving that every permitted number had an equal chance.

Why is random_state=42 so common?

This is a related convention, but it is not the same behaviour.

The scikit-learn glossary says that random_state controls the random-number generator used by an estimator or cross-validation splitter. Passing a fixed integer can make calls reproducible.

The glossary specifically names 0 and 42 as popular integer seeds and recommends checking stability across several distinct seeds. Seed 42 is therefore a convention, not a uniquely accurate or more random setting.

When an LLM answers 42, the result reflects learned token probabilities and cultural patterns. When code uses random_state=42, the number is an explicit seed chosen to make a randomised process reproducible.

What should you use instead?

  • If you need a fair or uniform draw, do not rely on an LLM's unaided text response because LLM-generated numbers show systematic biases.
  • If you need a reproducible machine-learning experiment, set an explicit integer seed and check the result across multiple distinct seeds.
  • If you are testing model behaviour, vary the prompt, range, language and temperature because each can affect the preferred answer.
  • Treat a different answer as variety, not proof of genuine randomness.

The wider lesson

The 42 habit is a neat example of how language models reproduce familiar human defaults. Similar issues appear when systems produce flattering or overly agreeable answers, explored in my article on agreeable AIs.

For practical habits around questioning model output rather than accepting it at face value, see how to keep your critical thinking sharp when using AI.

Bottom line

AIs do not always pick 42 or 17. They favour different numbers according to learned cultural patterns, prompt wording, model settings and the range offered.

The seed in random_state=42 serves a different purpose: it makes a randomised software process reproducible. In either case, 42 is familiar rather than magical.

Comments

No comments yet - start the conversation.

Leave a Comment

Your email address will not be published. No links allowed - keep it kind.