Random Number Generation Flashcards

All 3 cards in this deck

What is a random number in a program?

A number generated within a specified range that cannot be predicted.

Give two uses of random number generation in programs.

Any two: games of chance such as dice rolls; generating secure passwords; avoiding data collisions in network transmission.

What are the steps to select a random element from an array?

e.g. names holding "Ali", "Bea", "Cai"

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