Please enable JavaScript to use CodeHS

AI Literacy

Why does AI give a different answer every time?

Ask a chatbot the same question twice and the answers can change. That is on purpose. A chatbot picks each word from a list of chances, a bit like spinning a weighted spinner. Here is how it works, and how a setting called temperature turns the dial.

How AI works ~12 min 4 interactives

Same prompt, new answer

Example: The cat sat on the mat. Another run could say: The robot danced beside a volcano.

The short answer

Is AI random? Sort of, on purpose.

Ask a chatbot the same question twice and you may get two different answers. That is not a bug. It is how chatbots are built.

A chatbot runs on a language model. That is a program that learned patterns from a huge pile of text. Its main job is to guess the next word, one word at a time. (Want the full story? Read AI explained: next-word prediction.) Each step works like this:

  1. It makes a list

    The model gives every possible next word a score. The scores become chances, called probabilities. After "The cat sat on the", maybe "mat" gets 36% and "volcano" gets 4%.

  2. It picks one

    It does not always take the top word. It picks at random, but the chances count. Think of a spinner where likely words get big slices and unlikely words get thin ones.

  3. It repeats

    The chosen word joins the text. Then the model makes a new list for the word after that. One different pick early on can send the whole answer down a new path.

A small note: models really work with small chunks of text called tokens, not whole words. We say "words" here to keep things simple. (See how chatbots read tokens.)

So is AI random? The list of chances is not random. Give the model the same text and it builds the same list. The randomness comes from the picking step. A setting called temperature decides how adventurous that step is.


Try it: the picking step

The weighted spinner

Here is a list of chances for the next word. Each slice of the spinner is as big as that word's chance. Spin it once. Then spin it 100 times and watch the bars fill in.

Next-word chances

The cat sat on the ___

spin me

Press Spin once.

What the spinner gave you

0 spins

    The white tick is the real chance. The bar is what you got.

    Notice two things. First, "mat" wins most often, but not every time. Even "pizza" at 2% shows up now and then. Second, a few spins can look way off from the chances. After many spins, the bars settle close to the ticks.

    A chatbot answer is like one spin per word. One answer tells you very little about what the model "really thinks."


    Try it: the big one

    Temperature: the odds dial

    Temperature is a setting that changes how flat or sharp the chances are. It does not change which words the model knows. It changes how much the top words win.

    Low temperature = sharp

    The most likely word gets an even bigger share. It wins almost every time. Answers are predictable and can get repetitive.

    High temperature = flat

    The odds even out. Rare words get picked more. Answers feel fresh, but there are more odd choices and more mistakes.

    Use the lab. Drag the slider and watch the bars change. Then press Generate sentence a few times at temperature 0, and again at 2.

    Temperature lab

    Temperature1.00
    warm: balanced

    Chances for the last word

    The cat sat on the ___

      Total 100.0%

      Sentence maker

      Press Generate sentence.

      Last 5 sentences

      1. Nothing yet.

      This is a toy model. It knows only a few dozen words and a handful of tiny next-word tables that were written by hand. A real model has tens of thousands of tokens and learned its numbers from data. The math that reshapes the bars is the real formula, though.

      What you should have seen

      • At 0, the sentence never changes. At every step the model takes the top word.
      • Around 0.3 to 1, most sentences make sense, and some words change.
      • At 2, rare words win a lot. You get silly sentences, like a pizza dancing beside a volcano.

      People often say high temperature means "more creative." That is a nice way to put it, but the model is not getting braver or smarter. It is taking bigger risks. Sometimes a risk gives a fresh idea. Sometimes it gives a mistake.

      Temperature 0 in real chatbots. It makes repeats much more likely, but not certain. Tiny math differences on big computers, and model updates, can still change an answer.


      Related settings

      Top-k, top-p, and seed

      Temperature is not the only dial. Three more settings show up in AI tools, especially ones for developers.

      Top-k

      only the k best words

      Look at just the k most likely words and ignore the rest. If k is 3, the model spins only among its top 3 choices.

      Top-p

      only the best words that add up to p

      Keep the best words until their chances add up to p, like 80%. Drop the rest. When the model is sure, that may be one word. When it is unsure, it may be many.

      Seed

      the random starting point

      A computer makes "random" numbers from a formula that starts at a number called a seed. Same seed, same starting point, same picks. That makes a result repeatable.

      Try top-k and top-p on the same list of chances. Words that get cut can never be picked. The words that stay get scaled up so the chances add up to 100% again.

      Which words stay in the spinner?

        The seed idea shows up in the lab above. Turn on Fix the seed and press Generate sentence again and again. Every press starts from the same random numbers, so you get the same sentence. Scientists and software testers like this because they can repeat an experiment.


        Try it: decide

        Which setting would you pick?

        Different jobs want different settings. Pick low, medium, or high temperature for each job. There is not always one right answer, so you may see "close enough" feedback.

        Best picks: 0 of 6

        Math homework help

        You want the steps to solve 3x + 5 = 20.

        A poem about the ocean

        You want fresh, unexpected images.

        Writing code

        You want a function that sorts a list.

        Brainstorming team names

        You want 20 very different names for your robotics club.

        Summarizing an article

        You want the main points without made-up details.

        Telling jokes

        You want a joke that is surprising but still funny.


        Why it matters

        Why this matters for you

        Creative work likes variety

        When you ask for story ideas or team names, different answers are the whole point. Re-asking is a feature.

        Facts, math, and code do not

        There, you want the one right answer. Higher temperature gives wrong words more chances. And low temperature only makes the model consistent, not correct. It can repeat the same mistake every time.

        Asking twice can give two answers

        Say the model is only 55% sure about a fact. Close to half the time you would get something else. Each answer is one spin, not a final ruling.

        "It said it once" is not proof

        A screenshot shows one spin. It may be the rare slice. And two spins that agree can still both be wrong. Chatbots can sound sure either way. See AI hallucinations explained.

        How to verify an AI answer

        1. Ask again. Try two or three times, or rephrase. If the answers disagree, treat that as a warning sign.
        2. Check a trusted source. Use your textbook, a teacher, or a well-known reference for any fact that matters.
        3. Redo the math. Work the problem yourself, or plug the answer back in to see if it fits.
        4. Run the code. Test it with a few inputs, including odd ones, before you trust it.

        For the curious

        The math behind the dial

        This part is optional. It shows the real formula that the lab uses. It uses exponents and a little algebra, so high school math is plenty.

        Show me the softmax math

        Step 1: scores. For each possible next word, the model computes a score called a logit. It can be any number. A higher logit means a more likely word.

        Step 2: softmax. To turn scores into chances that add up to 1, we use a function called softmax. Temperature T goes inside it:

        In words: divide each score by T. Raise e (about 2.718) to that power, which makes every number positive and stretches the gaps. Then divide each result by the total so everything adds up to 100%.

        What T does. When T is small, dividing makes the gaps between scores huge, so the top word takes nearly everything. When T is 1, you get plain softmax. When T is large, every z/T gets close to 0, every e0 is 1, and the chances flatten toward equal. T = 0 would mean dividing by zero, so tools just pick the highest score (this is called greedy decoding, or argmax).

        A tiny example by hand

        Two words with scores z = 2 and z = 1:

        T = 0.5z/T = 4 and 2
        e^4 = 54.6, e^2 = 7.4
        chances 88% and 12%
        T = 1z/T = 2 and 1
        e^2 = 7.4, e^1 = 2.7
        chances 73% and 27%
        T = 2z/T = 1 and 0.5
        e^1 = 2.7, e^0.5 = 1.6
        chances 62% and 38%

        Now try it live

        This table uses the same eight scores as the lab. Move the slider and watch every column update.

        1.00
        Wordzz / Te^(z/T)Chance
        Total

        Quick answers

        Questions people ask

        Why does ChatGPT give different answers to the same question?

        It builds each answer one word at a time. For each word it makes a list of chances and picks one at random, weighted by those chances. Two runs can pick different words, and one different word can change everything after it.

        What is AI temperature?

        Temperature is a setting that makes the word chances sharper or flatter. Low means the top word almost always wins, so answers are predictable. High means rarer words get picked, so answers vary more and can have more mistakes.

        How do chatbots choose words?

        They score every possible next word, turn the scores into chances, then sample one word from the list. Settings like temperature, top-k, and top-p shape the list first. Then the chosen word is added and the process repeats.

        Is AI random?

        Partly. The chances a model computes are not random. The picking step is. Setting temperature to 0 or fixing a seed makes the picking repeatable, though real products can still vary a little.


        Check yourself

        Quick quiz

        1. You set temperature to 0 in the lab and press Generate five times. What happens?

        2. A friend says, "A chatbot told me this fact, so it must be true." What is the best reply?

        3. What does turning temperature up do?


        Keep learning how AI works

        Now you know where the "randomness" in a chatbot comes from. Next, see how models guess the next word, why they sometimes make things up, and how they cut text into tokens. Ready for more? Try a CodeHS course on AI.

        Part of the AI literacy tutorial collection. Browse all tutorials.