import random
from typing import List


def find_reflection_times(
        ir_duration_in_seconds: float,
        first_reflection_delay: float,
        n_early_reflections: int,
        early_reflections_delay: float,
        diffusion_delay_factor: float,
        diffusion_delay_random_range: float,
        random_numbers_generator: random.Random
) -> List[float]:
    """
    Find delays with which reflected waves arrive to a listener.

    :param ir_duration_in_seconds:
        duration of impulse response wave (in seconds)
    :param first_reflection_delay:
        time (in seconds) between original sound and its first reflection
    :param n_early_reflections:
        number of equally spaced reflections
    :param early_reflections_delay:
        time (in seconds) between successive early reflections
    :param diffusion_delay_factor:
        exponential decay factor for time between successive late reflections
    :param diffusion_delay_random_range:
        relative range where time between successive late reflections can randomly vary
    :param random_numbers_generator:
        random numbers generator
    :return:
        delays with which reflected waves arrive to a listener
    """
    reflection_times = [first_reflection_delay]
    for i in range(n_early_reflections - 1):
        next_reflection_time = reflection_times[-1] + early_reflections_delay
        reflection_times.append(next_reflection_time)
    delay_without_randomness = early_reflections_delay
    max_n_iterations = int(1e5)
    for _ in range(max_n_iterations):  # pragma: no branch
        delay_without_randomness *= diffusion_delay_factor
        random_number = random_numbers_generator.uniform(
            -diffusion_delay_random_range, diffusion_delay_random_range
        )
        delay = delay_without_randomness * (1 + random_number)
        reflection_time = reflection_times[-1] + delay
        if reflection_time < ir_duration_in_seconds:
            reflection_times.append(reflection_time)
        else:
            break
    return reflection_times