Concepts · Level 1 · Note 3
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.
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.
Animated: what temperature does to the draw
- The model has odds for each next word, then draws one. More odds means more tickets in the draw.
- Low temperature gives the favorite almost every ticket. Answers become predictable.
- High temperature flattens the odds. Long shots get picked more often, which reads as creative.
- Back at the middle setting, one draw picks "blue".
- Ask again and the draw can land on "gray". Same question, different answer.
- One refusal proves little. Resend a request many times with small changes to the wording and one version can get through. The random draw helps the attacker, and so do the changes.
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 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.
What the vendors say about temperature 0 and seeds
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 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.
Animated: a small model drafts, the big model checks
Kept for the answer
- A small, fast model drafts the next few words.
- The big model checks the whole draft in a single pass. Four words pass its check. One doesn't.
- Everything up to the first mismatch is kept.
- The big model writes the word it wanted, "fast", and drafting starts again from there.
- Five words for the price of one slow pass. The answers follow exactly the same odds as the big model working alone.
- The side effect: words now arrive in bursts, and the burst sizes depend on the text. Someone watching the traffic can use that rhythm as a fingerprint.
Speculative decoding, technically
Normal generation is serial. Google Research’s 2022 paper 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 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.
Animated: one model guessing several words ahead
Accepted this step
- A normal model produces one next word per step.
- Medusa adds small extra output layers, called heads. Each guesses a word further ahead, all at the same moment.
- The guesses are joined into candidate phrases and checked together in one step.
- The longest run that holds up is accepted. Here that is three words. The fourth guess is dropped.
- Several words per step with no second model. The paper reports speedups of a little over two times, and more on some tasks.
- Like speculative decoding, the number of words that land per step depends on the text. We found no attack study on Medusa itself.
Medusa heads, technically
The Medusa paper 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”, 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%.
Best-of-N jailbreaking: success after many tries
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: “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 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 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” 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.
- 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.
- Rate-limit repeated near-identical prompts. Ten thousand variations of one request from one account is a signal you can detect.
- 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.
- Log outputs as evidence. Keep the request, parameters, model version, full response and timestamp.
- 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.
- 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.
Sources (all checked 23 November 2026)
- Anthropic, Glossary (temperature): platform.claude.com
- Google Cloud, “Content generation parameters”: docs.cloud.google.com
- OpenAI, “Advanced usage” guide: developers.openai.com
- OpenAI Cookbook, “How to make your completions outputs consistent with the new seed parameter”: developers.openai.com
- Yuan et al., “Understanding and Mitigating Numerical Sources of Nondeterminism in LLM Inference”, 2025: arxiv.org/abs/2506.09501
- Leviathan, Kalman, Matias (Google Research), “Fast Inference from Transformers via Speculative Decoding”, 2022: arxiv.org/abs/2211.17192
- Chen et al. (DeepMind), “Accelerating Large Language Model Decoding with Speculative Sampling”, 2023: arxiv.org/abs/2302.01318
- Cai et al., “Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads”, 2024: arxiv.org/abs/2401.10774
- Hughes et al., “Best-of-N Jailbreaking”, December 2024: 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
- Weiss, Ayzenshteyn, Amit, Mirsky (Ben-Gurion University), “What Was Your Prompt? A Remote Keylogging Attack on AI Assistants”, 2024: arxiv.org/abs/2403.09751
- Cloudflare, “Mitigating a token-length side-channel attack in our AI products”, 14 March 2024: blog.cloudflare.com
- 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
- Microsoft Security, “Whisper Leak: A novel side-channel attack on remote language models”, 7 November 2025: microsoft.com
- OpenAI API reference, Chat Completions streaming events: developers.openai.com