Free revision guides

round, random and length: writing the whole call

National 5 Computing Science: Software design and development

National 5 uses three predefined functions: round, random and length. Most candidates can name them. The examiners' reports for 2023 and 2024 say marks are lost when the call is not written in full.

round

SET average TO round(average, 1)

Two parameters, in this order: the value to round, then the number of decimal places. If average holds 8.4667, it now holds 8.5. Using round is usually 2 marks: one for the function with its brackets, one for both parameters in the right order.

random

SET dice TO random(1, 6)

The two parameters are the lowest and highest values, and both ends can come up: this line gives 1, 2, 3, 4, 5 or 6. Using random can be worth 3 marks: the function, the right range, and storing the result in the variable the question names.

A common use is to pick a random item from an array. Array indexes start at 0, so for an array of 7 days the call is random(0, 6), not random(1, 7).

length

SET letters TO length(password)

length gives the number of characters in a string, or the number of items in an array. A "length check" is something different: a kind of validation. Writing "length check" when asked for the function does not gain the mark.

What gains the marks
  • The whole call: name, brackets and every parameter.
  • The result stored or used: SET dice TO random(1, 6), not just random(1, 6) on its own.
  • Python names are fine if you write in Python: round(average, 1), random.randint(1, 6) and len(password).

Try two exam-style questions

Choose an answer, say how sure you are, then press Check. Every wrong answer tells you why it is wrong.

The Round, random and length simulation
In the course: Round, random and length. Feed values into round, random and length and see what comes out, then predict the result yourself.

The full course covers every topic like this. Every topic in National 5 Computing Science has a short note, a simulation to try and a practice quiz with feedback on every answer, plus coding lessons, a full mock exam and a progress report for parents.

Create an accountTry more for freeAbout the course

More guides

This site is independent: it is not connected to the SQA or Qualifications Scotland. Points from the examiners' course reports are given in our own words.