import random
import time


def gen_random_delay(min_s=0, max_s=10):
    """Generate a delay function that waits a random amount of time.

    :param min_s: Minimum number of seconds to delay (float).
    :param max_s: Maximum number of seconds to delay (float).
    :return: A delay method suitable for passing to retry's delay_func kwarg.
    """
    def RANDOM_DELAY(attempt, max_attempts, *args, **kwargs):
        span = max_s - min_s
        sleep_time = min_s + (random.random() * span)
        time.sleep(sleep_time)
    return RANDOM_DELAY