#ChatGPT: Write a Python program which computes a random number in [0,1], # and repeats this process #until a smaller value is computed. # What is the average length of such a sequence? Expected answer is 2.7. # import random def generate_sequence(): count = 1 current_value = random.random() # First random number in [0, 1] while True: next_value = random.random() # Generate the next random number if next_value < current_value: break # Stop if the next number is smaller than the current one current_value = next_value count += 1 return count def average_length(num_trials): total_length = 0 for _ in range(num_trials): total_length += generate_sequence() return total_length / num_trials # Run the simulation with 100,000 trials num_trials = 100000 avg_len = average_length(num_trials) print(f"Average length of the sequence: {avg_len}")