LLM Temperature and Sampling Explained: Why the Same Prompt Gets Different Answers

· 17 min read

Ask ChatGPT, Claude, or Gemini the same question twice and you will often get two different answers. The wording changes. The order of a list changes. Sometimes a product that appeared in the first shortlist disappears from the second. If you are using AI inside your product, that variation can break a feature that worked perfectly in yesterday's demo. If you are trying to understand how AI engines talk about your company, it means a single screenshot tells you almost nothing.

The reason sits in one of the least understood parts of how large language models work: sampling, the step where a model turns a list of probabilities into actual words. Settings such as temperature, top-p, and top-k control how adventurous that step is. Other factors, from hardware to live web search, add variation that no setting can remove.

This guide explains, in plain English, why LLM answers vary, what temperature and the other sampling settings actually do, why "temperature zero" is not a guarantee of identical output, how to choose settings for real business tasks, and what all of this means for measuring whether AI engines recommend your brand. If you are new to the topic, start with our practical guide to large language models and our explainer on tokens and context windows, then come back.

Published November 23, 2026. This is an educational explainer for U.S. B2B SaaS teams. Parameter names, ranges, and defaults differ by provider and change over time, so check the current documentation for the model you use. Examples with numbers are illustrative unless a source is named.

The Short Answer: Models Predict Probabilities, Then Pick

A large language model does not store finished answers. It generates text one small piece at a time. Those pieces are called tokens; a token is often a word, part of a word, or a punctuation mark.

At each step, the model looks at everything written so far and produces a score for every token in its vocabulary, which can contain more than a hundred thousand options. Those scores are converted into probabilities that add up to 100 percent. Then something has to choose one token, append it to the text, and repeat the process for the next token.

Imagine the model has written "The best CRM for a small sales team is" and must choose what comes next. Its probabilities might look something like this (illustrative numbers):

If the system always picked the single most likely token, it would always write "often" here. If it picks randomly in proportion to the probabilities, it will write "often" about a third of the time and something else the rest of the time. Each choice changes everything that follows, because the next prediction depends on the words already written. A small difference in the fifth word can lead to a different structure, a different example, or a different product list by the fiftieth word.

That choosing step is decoding, and the random version of it is sampling. Most chat products sample, which is the main reason two runs of the same prompt rarely match word for word.

Why Not Always Pick the Most Likely Word?

Always choosing the top token is called greedy decoding. It sounds like the safest option, so why do AI products add randomness at all?

Because the most likely next word is not the same as the best answer. Researchers found years ago that text produced by always taking the most probable path tends to be bland, generic, and prone to repetition. In the paper The Curious Case of Neural Text Degeneration, Holtzman and colleagues showed that maximizing probability often produces text that loops on the same phrases, while human writing regularly uses words a model considers less likely. Their conclusion was that good generation needs some controlled randomness, not none.

There is also a practical reason. Many tasks benefit from variety: brainstorming names, drafting several subject lines, writing alternative product descriptions, or producing different examples for training material. A system that can only produce one answer for each prompt is less useful for creative work.

So providers sample, and they give developers settings to control how much.

Temperature, Explained Without Math

Temperature is a number that reshapes the probability list before a token is chosen.

Go back to the CRM example. At a low temperature, "often" might rise from 31 percent to 70 percent or more, and the long tail of odd options almost disappears. At a high temperature, "often" might fall to 15 percent while dozens of unusual tokens become realistic choices. Turn the temperature up far enough and the model starts producing text that reads as if it lost its train of thought.

A useful mental model is a dial between consistency and variety. Temperature does not make a model smarter, more creative in a deep sense, or more truthful. It only changes how often the model takes the less obvious path at each step.

Providers implement temperature with different ranges and defaults. In OpenAI's API reference, temperature for models that accept it ranges from 0 to 2. Anthropic's documentation uses a range of 0 to 1 with a default of 1. Google's Gemini API documentation describes temperature alongside top-p and top-k as generation settings. The same number can therefore mean different things across providers. A temperature of 1 on a 0-to-1 scale is the maximum; on a 0-to-2 scale it is the middle.

Top-p and Top-k: Cutting Off the Long Tail

Temperature reshapes the whole list. Two other common settings simply remove options from it before sampling.

Top-k

Top-k sampling keeps only the k most likely tokens and discards the rest. With top-k set to 40, the model chooses only among its 40 highest-scoring candidates. The approach was popularized in story-generation research such as Hierarchical Neural Story Generation by Fan and colleagues.

The weakness of top-k is that a fixed number fits some situations badly. When the model is very confident, 40 options includes many poor ones. When many words are reasonable, 40 may cut off good choices.

Top-p (Nucleus Sampling)

Top-p, also called nucleus sampling, was proposed in the Holtzman paper mentioned above. Instead of a fixed count, it keeps the smallest group of top tokens whose combined probability reaches a threshold p. With top-p at 0.9, the model keeps adding candidates from the top of the list until they cover 90 percent of the probability, then samples only from that group.

When the model is confident, the nucleus may contain just two or three tokens. When it is uncertain, the nucleus grows. That adaptive behavior is why top-p became a common default.

Other Settings You May See

A common piece of advice from providers is to adjust temperature or top-p, but not both at once. Changing both makes it hard to know which setting caused a change in behavior.

Why "Temperature Zero" Still Gives Different Answers

Many teams set temperature to 0, expect identical output every time, and are surprised when results still differ. There are several reasons.

Ties and Near-Ties

At temperature 0, most systems behave like greedy decoding and pick the top token. But when two tokens have nearly equal scores, tiny numerical differences can flip which one wins. One flipped token early in an answer can change everything after it.

Floating-Point Arithmetic and Batching

Models run on specialized chips that perform enormous numbers of calculations in parallel. Computers represent decimal numbers with limited precision, and adding the same numbers in a different order can produce very slightly different results. In a research post titled Defeating Nondeterminism in LLM Inference, Thinking Machines Lab explained that a major source of run-to-run variation in served models is that results can depend on how many other requests are processed together in the same batch, which changes the order of calculations. You do not control what other customers are sending at the same moment, so you do not control that factor either.

Provider Statements

Providers say this openly. Anthropic's documentation notes that even with a temperature of 0, results will not be fully deterministic. OpenAI introduced a seed parameter that aims for mostly repeatable output when the same seed and settings are used, while describing determinism as best effort, and it returns a system fingerprint that changes when the serving configuration changes. A changed fingerprint is a signal that the same request may now produce different output.

Model Updates

The model behind a name can change. Providers release dated versions, retire old ones, and update aliases such as "latest." If your application calls an alias, the model answering in March may not be the model answering in November. Pinning a specific dated version where your provider offers one gives you more stable behavior, at the cost of handling migrations yourself.

Reasoning Models

Some models that "think" before answering handle sampling differently. Certain reasoning models accept only the default temperature or ignore sampling settings, and their hidden reasoning can take a different path each run. Our explainer on reasoning models covers how those models work and when they are worth the cost.

Variation That Has Nothing to Do With Sampling

Sampling is the best-known source of variation, but in real AI products it is often not the largest. Consumer assistants such as ChatGPT, Gemini, Claude, Copilot, and Perplexity add layers that change the answer even if the underlying model were perfectly repeatable.

For anyone building an AI feature, most of these layers are under your control when you call a model API directly. For anyone measuring consumer AI answers, most of them are not.

Choosing Settings for Real Business Tasks

There is no universally correct temperature. The right setting depends on whether you want one dependable answer or a range of options. These starting points are illustrative; test them on your own task.

Tasks That Need Consistency

Extraction, classification, routing, data cleanup, and answering from approved documents should behave the same way every time. For these tasks:

Low temperature reduces variation, but it does not make a wrong answer right. A model that misunderstands a task at temperature 0 will usually misunderstand it consistently.

Tasks That Need Variety

Brainstorming, campaign ideas, alternative headlines, and creative drafts benefit from a moderate or default temperature. If the output starts to wander, lower the temperature or tighten top-p before rewriting the prompt.

Tasks Where Answers Can Be Checked

For math, logic, or code, one useful pattern is to generate several answers and compare them. The self-consistency technique described by Wang and colleagues samples multiple reasoning paths and chooses the most common final answer, which improved accuracy on reasoning benchmarks in their experiments. For code, running automated checks on several candidates can be more reliable than trusting a single output. Both approaches cost more because they multiply the number of model calls.

Leave Defaults Alone When the Provider Says So

Some providers now recommend leaving sampling settings at their defaults for their newest models, or do not expose them at all for certain models. Follow the current documentation. Changing settings that a model was not tuned for can make output worse rather than more reliable.

How to Test an AI Feature When Answers Vary

Variation changes how you should evaluate an AI feature. A single good result in a demo proves very little. A better process looks like this:

  1. Build a fixed test set. Collect real inputs from your task, including difficult and unusual ones.
  2. Run each input several times. Five to ten runs per input will show whether results are stable or scattered.
  3. Score the outcome that matters. Was the classification correct? Was the required field extracted? Did the answer stay within the approved documents?
  4. Report rates, not anecdotes. "Correct in 46 of 50 runs" is useful. "It worked when I tried it" is not.
  5. Record everything. Save the model version, settings, prompt version, date, and system fingerprint if available.
  6. Retest after every change. Prompt edits, model upgrades, and setting changes can all shift results.

Our guide to evaluating LLMs covers this process in more depth, including why public leaderboards rarely predict performance on your own work.

What Answer Variation Means for AI Brand Visibility

Everything above matters directly to companies trying to understand how AI engines describe and recommend them.

Suppose a founder asks ChatGPT, "What are the best project management tools for agencies?" and sees their product listed third. They take a screenshot and share it with the board. A week later, a sales rep asks the same question and the product is missing. Neither person did anything wrong. They each saw one sample from a system that varies.

That leads to a few practical rules.

One Answer Is an Anecdote

A single answer is one draw from a distribution of possible answers. It can show that a mention is possible. It cannot show how often it happens.

Report Mentions as X out of N

A meaningful observation repeats the same prompt several times under recorded conditions and reports the result as a count, such as "mentioned in 6 of 10 runs." Counts make it possible to compare engines, prompts, and dates honestly. Our guide on how to track LLM recommendations explains how to set up that kind of tracking.

Record the Conditions

Each observation should record the exact prompt, the engine and model where known, the date, the location and language, whether web search was used, and the verbatim answer with its citations. Without those details, nobody can tell whether a later difference reflects a real change or just a different sample.

Separate Surfaces

A model API and a consumer assistant are different systems. Answers from a developer API without web search tell you about the model's built-in associations. Answers from a consumer product with search, memory, and hidden instructions tell you about what a real buyer may see. Treat them as separate measurements and label them clearly.

Look for Trends, Not Single Changes

Because answers vary, a mention rate that moves from 5 of 10 to 6 of 10 may be noise. A rate that moves from 0 of 10 to 7 of 10 over several weeks, across several related prompts, is much stronger evidence that something changed. Even then, many factors outside your control can explain the change, so be careful about claiming cause and effect.

Make the Likely Path Point to You

Sampling settings decide how often a model takes a less obvious path. Your evidence affects what the obvious path is. When clear, consistent, crawlable facts about your product appear on your own site and on authoritative independent sources, a model is more likely to treat your brand as a strong candidate for a relevant question, and retrieval systems are more likely to find pages that support the answer. That does not guarantee a mention in every run, but it moves your brand from the long tail toward the top of the list. Our comparison of LLM SEO and traditional SEO covers how that evidence differs from classic ranking work.

Common Myths About LLM Randomness

Myth: Temperature 0 makes a model deterministic. It reduces variation but does not guarantee identical output, for the reasons covered above.

Myth: Higher temperature makes a model more creative or intelligent. It makes the model choose less likely words more often. That can produce fresher phrasing, but it also increases the chance of errors and nonsense.

Myth: Lower temperature makes answers more accurate. It makes answers more consistent. If the model's most likely answer is wrong, a low temperature makes the wrong answer appear more reliably.

Myth: Different answers mean the model is broken. Variation is expected behavior. It becomes a problem only when your task needs consistency and you have not designed for it.

Myth: You can control consumer chatbot settings. Consumer products generally do not let users set temperature, and they add search, memory, and routing on top. What you can control is the prompt you ask and how carefully you record the result.

A Practical Checklist

For teams building AI features:

For teams measuring AI brand visibility:

The Bottom Line

LLM answers vary because models choose each word from a set of probabilities, and because the products around them add search, memory, hidden instructions, and changing model versions. Temperature, top-p, and top-k let developers control part of that variation, but none of them can remove it entirely, and none of them make a model more truthful.

For product teams, the lesson is to design for variation: pick settings that match the task, enforce formats, ground answers, and test with repeated runs. For marketing and leadership teams, the lesson is to measure AI visibility the same way: with repeated, dated, recorded observations rather than single screenshots.

If you want to see how often AI engines actually mention your brand across real buyer questions, and which evidence may be missing, book a strategy call with LLM Recommend. For related reading, see our guides on how LLMs are trained, LLM bias, and small language models.

Frequently Asked Questions

Why does ChatGPT give different answers to the same question?

Language models choose each word by sampling from a set of probabilities, so small differences early in an answer lead to different wording, structure, and lists. Consumer assistants also add live web search, memory, location, hidden instructions, and model updates, all of which can change the answer between runs.

What does temperature mean in an LLM?

Temperature is a setting that reshapes the model's word probabilities before one is chosen. Low temperature makes likely words even more likely, producing more predictable output. High temperature flattens the probabilities, producing more varied and sometimes less coherent output. Ranges and defaults differ by provider.

What is the difference between temperature and top-p?

Temperature reshapes the entire probability list. Top-p, or nucleus sampling, removes unlikely options by keeping only the smallest set of top words whose combined probability reaches a threshold, then samples from that set. Providers generally suggest adjusting one or the other rather than both.

Does temperature 0 make an LLM deterministic?

No. Temperature 0 greatly reduces variation, but near-ties between words, floating-point arithmetic, request batching on shared hardware, and model updates can still produce different outputs. Providers including Anthropic and OpenAI state that identical output is not guaranteed.

What temperature should I use for business tasks?

Use a low temperature for extraction, classification, and answers that must follow approved documents, combined with clear instructions, structured outputs, and validation. Use a moderate or default temperature for brainstorming and drafting. Follow provider guidance where it recommends keeping defaults for a model.

How should I measure whether AI engines recommend my brand if answers vary?

Repeat each buyer question several times per engine, report mentions as a count such as 6 of 10 runs, and record the prompt, engine, model, date, location, search mode, verbatim answer, and citations. Track trends over weeks rather than relying on a single screenshot, and keep API and consumer assistant results separate.