A programmer is reviewing how Python's built-in random module behaves before using it in a classroom simulation and a login system. Which of the following statements about the random module are true? Select all that apply.
random.random() can occasionally return exactly 1.0, though this is very rare.
The numbers come from a deterministic algorithm, so they are pseudo-random.
Calling random.seed(42) first reproduces the same results across runs using the same Python version and identical ordered calls and inputs, with no intervening reseeding or concurrent access to the generator.
Since the default seed comes from the system, random is safe for generating passwords.
random.choice(items) returns one element of a non-empty list, with each list position equally likely to be selected.
Unlock full course notes by signing up
Expected count from a probability simulation
A student simulates a basketball player who makes 35% of free throws. The program below runs 400 simulated attempts:
The printed number changes from run to run. On average over many runs, what value is printed? Give your answer as a whole number.
Comparing two colour-weight schemes
A game selects one colour using the following Python code. Assume random has already been imported.
The developer then considers replacing the weights with [4, 10, 6], keeping the colour order unchanged. The figure compares these two schemes.
Complete the table with the probability that the single selected colour is each listed colour. Enter exact decimals between 0 and 1, rather than percentages.
Sampling tokens with repeated labels
A workshop represents six physical activity tokens using this Python list. Each list entry represents a separate token, even when its label repeats. Assume random has already been imported.
Across all possible results of this call, determine the smallest and largest possible number of art tokens in picked. Also determine the smallest and largest possible number of different activity labels in picked. For example, two music tokens contribute two tokens but only one different label.
Enter all four counts as exact whole numbers.