# Temperature 0 is not deterministic: what randomness does to AI security

> Temperature sampling, speculative decoding and Medusa heads in plain words, then the security side: retry jailbreaks, incidents you can't replay, and streaming side channels.

- Published: 2026-11-23
- Topics: AI security, LLM security, Side channels
- Canonical page: https://thesecguy.com/notes/temperature-speculative-decoding-side-channels/
- Publisher: The Sec Guy (https://thesecguy.com)

**Short answer:** A language model picks each next word by a weighted draw, and temperature sets how adventurous the draw is. Anthropic and Google say even temperature 0 doesn't guarantee the same answer twice, and OpenAI says its outputs aren't deterministic by default. One refusal proves little: the Best-of-N study hit 89% success on GPT-4o by resending reworded versions of a prompt up to 10,000 times. Streaming adds a second problem: the size and timing of the chunks can reveal an answer's topic to someone watching encrypted traffic. Test many times, log the exact output, and keep streaming padding on.

---

Ask a language model the same question twice and you may get two different answers. That's by design, and it has security consequences. One passing run of a safety test doesn't tell you the next run will pass, and an incident can be hard to replay. Separately, the way an answer streams back to you can give away what it's about.

Underneath are temperature sampling, speculative decoding and Medusa heads. We explain each in plain words first, then technically.

## Temperature, in plain words

When a model is about to write its next word, it has a shortlist with odds: "blue" 60%, "gray" 25%, "falling" 10%, and a long tail of unlikely words. It then draws one, like a lottery where likelier words hold more tickets.

Temperature decides how the tickets are handed out. Turn it down and the favorite gets nearly all of them. Turn it up and the long shots get a fairer chance, which reads as more creative and less predictable. At zero the model is meant to take the favorite every time.

<figure class="fig">
<p class="fig-k">The same shortlist at three temperature settings</p>
<div class="hbars">
<div class="hbar hot"><em>Low temperature: "blue" takes nearly every ticket</em><div class="track"><i style="width:96%"></i></div><b>almost</b></div>
<div class="hbar"><em>Middle: "blue"</em><div class="track"><i style="width:60%"></i></div><b>60%</b></div>
<div class="hbar"><em>Middle: "gray"</em><div class="track"><i style="width:25%"></i></div><b>25%</b></div>
<div class="hbar"><em>Middle: "falling"</em><div class="track"><i style="width:10%"></i></div><b>10%</b></div>
<div class="hbar"><em>High temperature: the long shots catch up</em><div class="track"><i style="width:40%"></i></div><b>closer</b></div>
</div>
<figcaption>Our illustration, using the example odds from the paragraph above. Real models have tens of thousands of candidates.</figcaption>
</figure>

## Temperature, technically

The model produces a score for every token in its vocabulary. Those scores are divided by the temperature and turned into probabilities. A [Princeton paper](https://arxiv.org/abs/2310.06987) we come back to below describes temperature as the parameter that "controls the sharpness of the next-token distribution". Low values sharpen it toward the top choice. High values flatten it.

Two more settings trim the shortlist before the draw. Top-K keeps only the K most likely tokens. Top-P keeps the most likely tokens until their probabilities add up to P. Google's documentation gives the order: top-K first, "Then tokens are further filtered based on top-P with the final token selected using temperature sampling."

At temperature 0, Google says "the highest probability tokens are always selected." You'd expect that to give the same answer every time. Anthropic and Google say it doesn't, and OpenAI says its outputs aren't deterministic by default.

<figure class="fig">
<p class="fig-k">What the vendors say about temperature 0 and seeds</p>
<div class="flow">
<div class="node"><b>Anthropic</b><span>"Even with temperature set to 0, the results will not be fully deterministic"</span><div class="chips"><i class="chip">glossary</i></div></div>
<div class="node"><b>Google</b><span>"mostly deterministic, but a small amount of variation is still possible"</span><div class="chips"><i class="chip">Google Cloud docs</i></div></div>
<div class="node"><b>OpenAI</b><span>"Chat Completions are non-deterministic by default"</span><div class="chips"><i class="chip">API guide</i></div></div>
</div>
<figcaption>Source: each vendor's documentation, read 23 November 2026.</figcaption>
</figure>

OpenAI offers a `seed` setting and says it will "make a best effort to sample deterministically", then adds: "Determinism is not guaranteed". The one cause it names is its own side: "determinism may be impacted due to necessary changes OpenAI makes to model configurations".

Research points to arithmetic as well. A [2025 paper](https://arxiv.org/abs/2506.09501) traced the variation to "the non-associative nature of floating-point arithmetic". The same sums done in a different order, on different hardware or with a different batch size, round slightly differently, and a near-tie between two words can flip. In its tests, with the model always taking the favorite, one model's accuracy still moved by up to 9% between setups.

## Speculative decoding, in plain words

A senior editor writes well but slowly. So a junior writer drafts the next few words, and the editor checks the draft in one glance. Every word the editor would have written anyway is kept. At the first word the editor disagrees with, the editor writes that word and the junior starts drafting again from there.

When the model is drawing at random, the check is a weighted coin flip in place of an exact match, tuned so the result follows the editor's odds.

When the junior guesses well, several words land for the price of one check. When the text is hard to predict, fewer do.

<figure class="fig">
<p class="fig-k">Junior drafts, senior checks</p>
<div class="flow">
<div class="node"><b>1. Draft</b><span>A small, fast model guesses the next few words</span><div class="chips"><i class="chip">the</i><i class="chip">cat</i><i class="chip">ran</i><i class="chip">very</i><i class="chip">fast</i></div></div>
<div class="node"><b>2. Check</b><span>The large model scores all of them in one pass</span><div class="chips"><i class="chip">one pass</i></div></div>
<div class="node"><b>3. Keep</b><span>Every word up to the first disagreement stays</span><div class="chips"><i class="chip">keep</i><i class="chip">keep</i><i class="chip">keep</i><i class="chip">keep</i><i class="chip">reject</i></div></div>
<div class="node"><b>4. Fix and repeat</b><span>The large model writes the rejected word, then drafting restarts</span><div class="chips"><i class="chip">same quality, sooner</i></div></div>
</div>
<figcaption>Our illustration of the method in the Google Research and DeepMind papers.</figcaption>
</figure>

## Speculative decoding, technically

Normal generation is serial. Google Research's [2022 paper](https://arxiv.org/abs/2211.17192) puts it this way: "decoding K tokens takes K serial runs of the model." Speculative decoding has a small draft model propose a few tokens, then lets the large model score all of them in a single parallel pass. DeepMind's [paper on the same idea](https://arxiv.org/abs/2302.01318) notes that scoring a short run of tokens in parallel "has a very similar latency" to producing one.

A drafted token is kept or rejected by comparing the two models' probabilities, and a rejected one is redrawn from an adjusted distribution. The method works by "guaranteeing that the outputs from our system have the same distribution as those from the target model alone." You get answers that follow the big model's odds exactly, sooner.

On speed, the Google paper reports "a 2X-3X acceleration" on its test model, and DeepMind "a 2–2.5× decoding speedup" on a 70 billion parameter model. The "3x" you see on slides is the top of that range.

## Medusa heads, in plain words

Same goal, no junior writer. One writer guesses the next several words at once and then checks which guesses hold up together.

<figure class="fig">
<p class="fig-k">One model guessing several words ahead</p>
<div class="flow">
<div class="node"><b>1. Normal output</b><span>The model predicts the next word as usual</span><div class="chips"><i class="chip">word 1</i></div></div>
<div class="node"><b>2. Extra heads</b><span>Small add-on layers guess the words after that, at the same time</span><div class="chips"><i class="chip">word 2</i><i class="chip">word 3</i><i class="chip">word 4</i></div></div>
<div class="node"><b>3. Check together</b><span>The candidates are tested as a tree in one step</span><div class="chips"><i class="chip">tree check</i></div></div>
<div class="node"><b>4. Accept</b><span>The longest run that passes is kept</span><div class="chips"><i class="chip">several words per step</i></div></div>
</div>
<figcaption>Our illustration of the design in the Medusa paper.</figcaption>
</figure>

## Medusa heads, technically

The [Medusa paper](https://arxiv.org/abs/2401.10774) adds small extra output layers to a single model: "Medusa heads are additional decoding heads appended to the last hidden states of the original model." The first head guesses the token after next, the second the one after that, and so on. The candidates are checked together with "a tree-structured attention mechanism", and the longest run that passes is accepted.

There's "no requirement for a draft model", which makes it easier to deploy. The reported speedup is "over 2.2×" for the simpler version. For the fuller one the paper's text says 2.3 to 2.8 times, while its arXiv summary says 2.3 to 3.6. One difference from speculative decoding matters: Medusa's "typical acceptance" rule, offered as an alternative to the stricter check, doesn't try to reproduce the original model's output distribution exactly. The authors argue "it is typically unnecessary to match the distribution of the original model."

## Security problem 1: one test run proves little

If outputs vary, so do refusals. An attacker can skip the clever prompt and just keep resending.

The clearest evidence is ["Best-of-N Jailbreaking"](https://arxiv.org/abs/2412.03556), published in December 2024 by researchers from Anthropic, Stanford, Oxford and others. They took a harmful request, made random small changes "such as random shuffling or capitalization", and kept resending. They report "89% on GPT-4o and 78% on Claude 3.5 Sonnet when sampling 10,000 augmented prompts." Even 100 tries got through 41% of the time on Claude 3.5 Sonnet. Success grew with the number of tries in a steady, predictable curve.

The attack was "still effective" at temperature 0, so turning temperature down is no defense. The paper puts much of the effect down to the small changes in the input, with the random draw adding to it. And when the researchers replayed a prompt that had worked, at temperature 1, it produced harmful output only "approximately 20% of the time" in the paper's summary, and between 15% and 30% in its detailed results depending on the type of input. At that setting the same input gave a different result most of the time.

The Princeton paper is the mirror image for open models. By removing the system prompt (the builder's standing instructions) and trying different temperature, top-K and top-P values, the authors raised the rate of harmful answers "from 0% to more than 95% across 11 language models". They note that models are "usually evaluated for alignment using only default generation methods." On a hosted model, gpt-3.5-turbo, the same trick managed 7%.

<figure class="fig">
<p class="fig-k">Best-of-N jailbreaking: success after many tries</p>
<div class="hbars">
<div class="hbar hot"><em>GPT-4o, 10,000 tries</em><div class="track"><i style="width:89%"></i></div><b>89%</b></div>
<div class="hbar"><em>Claude 3.5 Sonnet, 10,000 tries</em><div class="track"><i style="width:78%"></i></div><b>78%</b></div>
<div class="hbar"><em>Claude 3.5 Sonnet, 100 tries</em><div class="track"><i style="width:41%"></i></div><b>41%</b></div>
</div>
<figcaption>Source: Hughes et al., "Best-of-N Jailbreaking", December 2024. These are the models tested at that time.</figcaption>
</figure>

## Security problem 2: you can't replay an incident

When something goes wrong, the first instinct is to send the same prompt again and watch what happens. With a model that may not show you what the user saw.

So the evidence has to be captured at the time. Log the full request, the settings, and the exact output. If you use OpenAI, log the `system_fingerprint` it returns too, which "represents the backend configuration that the model runs with" and tells you when OpenAI's backend configuration has changed. This logging advice is ours. The vendors document the variation but don't spell out what to keep.

## Security problem 3: the rhythm of the answer leaks

Chat apps stream answers a few tokens at a time. The traffic is encrypted, but someone on the network path can still see the size and timing of each chunk. A leak like that is called a side channel.

In March 2024 researchers at Ben-Gurion University showed [what that gives away](https://arxiv.org/abs/2403.09751): "the size of the packets can reveal the length of the tokens." From lengths alone they could "accurately reconstruct 29% of an AI assistant's responses" and infer the topic of 55% of them, in tests on ChatGPT-4 and Microsoft Copilot. Cloudflare [responded the same day](https://blog.cloudflare.com/ai-side-channel-attack-mitigated) by adding random padding to its AI products, and said it had "not seen any malicious attacks exploiting this vulnerability".

Speculative decoding makes the pattern richer. A University of Toronto team [showed](https://arxiv.org/abs/2411.01076) that "input-dependent patterns of correct and incorrect speculations can be inferred" by counting tokens per step. In the current version of their paper they could tell which of 50 known prompts a user had sent "with over 75% accuracy" across four speculative methods at a low temperature setting, and at 100% for one of them, against 2% for a blind guess. We didn't find a study that tested Medusa itself. Our reading is that it belongs to the same family, since it also releases tokens in bursts whose size depends on the text.

Microsoft's ["Whisper Leak"](https://microsoft.com/en-us/security/blog/2025/11/07/whisper-leak-a-novel-side-channel-cyberattack-on-remote-language-models/) research in November 2025 took it to scale: a classifier trained on encrypted traffic could flag conversations about one chosen sensitive topic, and "for many models, the cyberattack achieved scores above 98%" in controlled tests. Microsoft reports that "OpenAI, Mistral, Microsoft, and xAI have deployed protections at the time of writing." OpenAI's API now adds "an obfuscation string added to normalize the size of streamed chunks", included by default.

**Medusa heads: our own reasoning.** We found no paper that attacks Medusa heads by name, so this part is ours and unmeasured. Two things follow from the design. First, Medusa also accepts a varying number of guessed words per step, and how many it accepts depends on how predictable the text is. That is the same kind of signal the speculative decoding research measured, so assume the same leak until someone shows otherwise, and apply the same padding. Second, the extra heads are extra trained weights, often added by someone other than the model's author. They only propose words, and the method keeps or rejects each proposal by its own acceptance rule, so treat a model with added heads as a changed model: get it from a source you trust and test it again.

## What to check, with an example

Say you run a health information chatbot. It has passed a safety review, a user has complained about an answer, and people ask it about conditions they'd prefer to keep private. All three problems apply.

1. **Run every safety test many times.** Record a pass rate, never a single pass or fail. Include changed capitalization, spacing and word order in the test set, because that's what Best-of-N does.
2. **Rate-limit repeated near-identical prompts.** Ten thousand variations of one request from one account is a signal you can detect.
3. **Test the settings your users can change.** If your app exposes temperature or top-P, or runs without a system prompt in some path, test those paths too.
4. **Log outputs as evidence.** Keep the request, parameters, model version, full response and timestamp.
5. **Leave streaming padding on.** If your provider offers an obfuscation or padding option, don't disable it to save bytes. If you host the model yourself, add padding or send tokens in grouped batches, which are the mitigations the research papers propose. Padding and batching reduce the leak without removing it, so for the most sensitive uses consider turning streaming off.
6. **Ask your serving team what speed-ups are enabled.** Speculative decoding is often a server flag. Knowing it's on tells you which of these side channels apply to you.

The model's own refusal is the first layer. The limits and logs around it are the ones you own, as we set out in [LLM security: the risks, the fixes and where to start](https://thesecguy.com/notes/llm-security-guide/).

---

**Sources** (all checked 23 November 2026)
- Anthropic, Glossary (temperature): [platform.claude.com](https://platform.claude.com/docs/en/resources/glossary)
- Google Cloud, "Content generation parameters": [docs.cloud.google.com](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/content-generation-parameters)
- OpenAI, "Advanced usage" guide: [developers.openai.com](https://developers.openai.com/api/docs/guides/advanced-usage.md)
- OpenAI Cookbook, "How to make your completions outputs consistent with the new seed parameter": [developers.openai.com](https://developers.openai.com/cookbook/examples/reproducible_outputs_with_the_seed_parameter)
- Yuan et al., "Understanding and Mitigating Numerical Sources of Nondeterminism in LLM Inference", 2025: [arxiv.org/abs/2506.09501](https://arxiv.org/abs/2506.09501)
- Leviathan, Kalman, Matias (Google Research), "Fast Inference from Transformers via Speculative Decoding", 2022: [arxiv.org/abs/2211.17192](https://arxiv.org/abs/2211.17192)
- Chen et al. (DeepMind), "Accelerating Large Language Model Decoding with Speculative Sampling", 2023: [arxiv.org/abs/2302.01318](https://arxiv.org/abs/2302.01318)
- Cai et al., "Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads", 2024: [arxiv.org/abs/2401.10774](https://arxiv.org/abs/2401.10774)
- Hughes et al., "Best-of-N Jailbreaking", December 2024: [arxiv.org/abs/2412.03556](https://arxiv.org/abs/2412.03556)
- Huang, Gupta, Xia, Li, Chen (Princeton University), "Catastrophic Jailbreak of Open-source LLMs via Exploiting Generation", 2023: [arxiv.org/abs/2310.06987](https://arxiv.org/abs/2310.06987)
- Weiss, Ayzenshteyn, Amit, Mirsky (Ben-Gurion University), "What Was Your Prompt? A Remote Keylogging Attack on AI Assistants", 2024: [arxiv.org/abs/2403.09751](https://arxiv.org/abs/2403.09751)
- Cloudflare, "Mitigating a token-length side-channel attack in our AI products", 14 March 2024: [blog.cloudflare.com](https://blog.cloudflare.com/ai-side-channel-attack-mitigated)
- Wei et al. (University of Toronto), "When Speculation Spills Secrets: Side Channels via Speculative Decoding In LLMs", version 4, February 2026: [arxiv.org/abs/2411.01076](https://arxiv.org/abs/2411.01076)
- Microsoft Security, "Whisper Leak: A novel side-channel attack on remote language models", 7 November 2025: [microsoft.com](https://microsoft.com/en-us/security/blog/2025/11/07/whisper-leak-a-novel-side-channel-cyberattack-on-remote-language-models/)
- OpenAI API reference, Chat Completions streaming events: [developers.openai.com](https://developers.openai.com/api/reference/resources/chat/subresources/completions/streaming-events.md)
