Sampling
Drawing one candidate at random, weighted by how likely it is
- Sampling is the act itself of drawing one candidate for the next word, weighted by how likely it is.
- It's not a free-for-all draw. The more likely a word is, the more often it gets drawn, and unlikely words only turn up now and then.
- A draw happens fresh for every single piece. One answer can contain hundreds of draws.
- Always picking the top choice is possible too, but doing that makes the same phrases loop and the writing go stiff.
- The dials that adjust the odds before a draw are temperature and top-p sampling. The draw itself comes after that.
Contents
1The analogy
Picture a raffle drum at a fair. Instead of one ticket per prize, the popular prizes each get several tickets in the drum, while a rare prize only gets one. Close your eyes and pull a ticket, and a prize with many tickets comes up often. The one-ticket prize still turns up now and then, just rarely.
This is how AI settles on the next word. The model scores every candidate for how likely it is each time — a likely word gets several tickets in the drum, an unlikely one gets just one. Pulling a ticket from that drum is sampling.
Once a ticket is pulled, the whole drum gets emptied out. What just got drawn becomes the new context, and the drum for the next piece is filled from scratch. That's why asking the same question twice can pull a different ticket, and get a different answer.
2In detail
The drum gets refilled for every piece
A piece of writing is built one piece at a time. Every time a piece gets added, the model rereads everything written so far and re-scores how likely each candidate for the next spot is. What ends up in the drum, and how many tickets each thing gets, changes every time.
The drum after "for lunch today" and the drum after "the capital of France is" look completely different. The first is full of dozens of plausible tickets; in the second, one candidate takes up almost the whole drum.
So the draw being random doesn't send the writing off the rails — filling the drum is the model's job, guided by context. What's random is the hand pulling the ticket, not what's inside the drum.
What happens if the top choice always wins
There's also a method that just grabs whichever candidate has the most tickets, every time — counting and choosing rather than drawing. It works fine for questions with one settled answer.
The trouble shows up in longer writing. Stringing together the single safest word every time makes sentences stiff and phrases repeat. Push it far enough and the same sentence can loop over and over. The safest word after a safe word tends to be another safe word, and there's no way out of that loop.
Drawing by likelihood breaks the loop. Every so often the second or third choice gets pulled instead, and the sentence heads down a different path. This bit of wobble does a lot of the work in making writing read as if a person wrote it.
Dials that adjust the drum before the draw
The draw itself is simple. What's not simple are two settings that adjust the drum right before the draw happens.
Temperature widens or narrows the gap in ticket counts. Lower it and the top candidate takes up nearly the whole drum; raise it and lower-ranked candidates get a fair number of tickets too. It leaves the order alone and only changes the gap.
Top-p sampling removes the bottom tickets from the drum entirely. Candidates get added in order of likelihood until a set share is filled, and whatever's left over never makes it into the drum at all. A ticket that was never in the drum can never be drawn, no matter how many times you try.
The two settings tidy up the drum, and sampling is what pulls one ticket out of it. Keeping that order straight is the key to not mixing the three up.
Why the same question gets a different answer
Ask an AI the same question twice and the answer comes out a little different each time. That's not a glitch — it's the draw doing exactly what it's supposed to. A different ticket getting pulled at the first piece means a different drum for the next one, and after a few pieces the whole answer has gone down a different path.
One small difference snowballs, so a slight fork early on can end up changing the conclusion. Running an answer several times can even show where a model is confident and where it isn't — a spot that comes back the same every time is one the model is sure of, and a spot that keeps changing is one it's shakier about.
To get the same result back on demand, the starting value fed into the draw can be locked in place — like fixing the exact habit of the hand shaking the drum.
Where it fits and where it doesn't
Stories, ad copy, name candidates — anything where seeing several different directions is useful is a good fit for drawing. Run the same request a few times and different options pile up.
Cleaning up numbers or filling out a fixed-format document is a different story — wobble just gets in the way there. It helps to tighten the settings so the drum stays nearly full of one candidate, or to just take the top choice outright, so results are easier to check.
Either way, drawing doesn't decide whether an answer is true. If the drum is full of wrong tickets, wrong words come out no matter how they're drawn. The draw only shapes the texture of the writing.
3More precisely
Sampling is the process of drawing an actual value from the probability distribution a model produces. The umbrella term for how this step gets handled while generating text is decoding, and it sits alongside always taking the maximum, or tracking several branches at once and comparing them. Temperature and top-p reshape the distribution before the draw happens, so they sit on a different layer from the drawing rule itself.
The analogy breaks down in a few places. Tickets in a drum can be counted one by one, but real-world likelihood is a smooth, unbroken value, so a share as fine as three in ten thousand is handled without trouble. There's no actual shaking motion either — a random number within a set range gets drawn, and the calculation checks which candidate's share that number falls into. And the drum is rebuilt entirely from scratch every single time; the drawn ticket doesn't just get quietly removed from a running drum — the whole drum is recalculated over context that now includes the previous result, tickets and all, starting completely from the ground up.
4Try it yourself
5Common misconceptions
It's easy to think an AI is inventing an answer at random, but actually it draws based on likelihood scored from context, so it isn't producing just anything.
It's easy to think a changing answer means the model is confused, but actually that's a natural result of a process that includes a random draw.
It's easy to think always taking the top choice makes answers more accurate, but actually it just makes phrases loop more easily, with no guarantee the facts improve.
7One-line summary
In shortSampling is drawing one ticket from a drum stacked with more tickets for popular prizes, choosing the next word weighted by how likely each candidate is.
Spotted an error or have a better analogy? Suggest an edit · Last updated2026-09-02