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.
namesholding "Ali", "Bea", "Cai"- Generate a random index in range:
i = random(0,2) - Use it as the index:
chosen = names[i] - Use the value:
print(chosen)→ e.g.Bea
- Generate a random index in range: