Random Number Generation Flashcards

All 4 cards in this deck

What is a random number in a program?

A number generated within a specified range so that its value is not known in advance, e.g. RANDOM_INT(1, 6) to simulate a dice roll.

Give two uses of random number generation in programs.

Any two, e.g.: simulating dice rolls or shuffling cards in games; choosing random questions in a quiz; generating random passwords or test data.

How do you select a random element from an array in AQA pseudo-code?

e.g. names ← ['Ali', 'Bea', 'Cai']

  1. Generate a random index in range: i ← RANDOM_INT(0, 2)
  2. Use it as the index: chosen ← names[i]
  3. Use the value: OUTPUT chosen → e.g. Bea

What does RANDOM_INT(1, 6) return in AQA pseudo-code?

A random integer from 1 to 6, with both 1 and 6 included.