AQA · GCSE · Computer Science

    Course version: 8525 · Version from Sept 2020

    Be able to use random number generation. Students will be expected to use…

    Full specification wording

    Random number generation in a programming language: Be able to use random number generation. Students will be expected to use random number generation within their computer programs. An understanding of how pseudo- random numbers are generated is not required.

    Random number generation lets a program produce unpredictable values, for example to simulate a dice roll or shuffle a quiz question.

    Checked against the AQA 8525 specification (opens in a new tab) on .

      Study notes

      From the checked teaching notes for this specification point.

      The idea

      Random number generation lets a program produce unpredictable values, for example to simulate a dice roll or shuffle a quiz question. In Python you import the random module and call random.randint(1, 6) to get a whole number from 1 to 6 inclusive, or random.random() for a value between 0 and 1. You must be able to use these calls inside your own programs, storing the result in a variable and using it in output or decisions. You are not required to understand how pseudo-random numbers are generated internally; you only need to use the facility correctly. Note the range is inclusive at both ends for randint.

      What earns the marks

      • Selects an appropriate random function call, e.g. random.randint(1, 6), to produce a value in a required range.
      • Recognises that randint includes both endpoints of the stated range.
      • Uses the generated value correctly, e.g. stored in a variable and used in output or a condition.
      • Distinguishes using random generation from explaining how pseudo-random numbers are produced, which is not required.

      Common mistakes and how to put them right

      • Assuming randint(1, 6) excludes 6.

        Put it right by stating both endpoints are included.

      • Forgetting to import the random module before calling its functions.

        Put it right by adding the import statement.

      • Believing you must explain the pseudo-random algorithm.

        Put it right by noting only correct use is required.

      Exam tips

      • Check the required range and choose a function whose endpoints match it.
      • Confirm the module import appears before any random call in the code.
      • Trace what value the variable holds after the call before predicting output.

      Try the lesson

      The start of the Random number generation in a programming language: Be able to use random number generation. Students will be expected to use random number generation within their computer programs. An understanding of how pseudo- random numbers are generated is not required. lesson, made from checked teaching notes for this specification point.

      Have a go first

      A program needs to simulate rolling a standard six-sided die, giving a whole number from 1 to 6 each time. Which use of random number generation achieves this?

      There is more to this lesson

      The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.

      Carry on with the full lesson

      A week of Premium from your first lesson · Then the free plan continues · No card, no charge

      Test your understanding of Random number generation in a programming language: Be able to use random number generation. Students will be expected to use random number generation within their computer programs. An understanding of how pseudo- random numbers are generated is not required.

      Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.

      Take topic quiz

      A week of Premium from your first lesson · Then the free plan continues · No card, no charge