# Temperature and Sampling: the LLM Creativity Dial

> Source: <https://dev.to/dev48v/temperature-and-sampling-the-llm-creativity-dial-975>
> Published: 2026-06-20 07:06:26+00:00

Why does the same prompt give different answers? Temperature. One number turns an LLM from "safe and repetitive" to "creative and risky" by reshaping the next-word odds before it picks. Drag the dial and watch.

🌡️ **Reshape + sample:** [https://dev48v.infy.uk/ai/days/day9-temperature.html](https://dev48v.infy.uk/ai/days/day9-temperature.html)

At each step it produces a probability for every possible next word — "weather is ___" → 46% sunny, 22% cloudy, 14% rainy, plus a long tail. Choosing one is a separate step called sampling.

```
p = Math.pow(p, 1 / temperature);  // then renormalise
```

Then it samples weighted by the reshaped probabilities, so two runs differ at higher T.

Pure temperature can still pick something absurd from the tail. **top-k** keeps only the k likeliest words; **top-p (nucleus)** keeps the smallest set summing to p (e.g. 0.9). Both cut the weird tail while keeping variety.

Facts, code, extraction → temperature ≈ 0 (reproducible). Brainstorming, copy, fiction → 0.7–1.0. Set temperature OR top-p, not both hard.

[Drag the dial](https://dev48v.infy.uk/ai/days/day9-temperature.html) — low = same word every time, high = scattered.
