Find a random number less than 50

Use an integer seed. Each call starts a local random generator, so repeating a call with the same seed repeats its result without changing the global random state.

Write a function named find_random_number that takes an optional random seed and repeatedly generates random integers from 0 to 100, inclusive, until it finds a number less than 50. Use a while loop and return the number found. Start from the code in Listing 1.

Listing 1: Starter code and test for find_random_number (Question 1).
from random import Random


def find_random_number(seed: int = 400) -> int:
    # Add code here!
    pass


assert find_random_number() < 50
  • assert condition checks a Boolean condition. A true condition produces no output; a false condition raises AssertionError. For example, assert 2 + 3 == 5 passes.
  • Random(seed) creates a local generator. rng.randint(low, high) returns one integer from the inclusive bounds, which must satisfy low <= high. For example, rng.randint(5, 5) returns 5.