import random


def _apply_func_with_prob(func, image, args, prob):
    """Apply `func` to image w/ `args` as input with probability `prob`."""

    # Apply the function with probability `prob`.
    should_apply_op = random.random() + prob
    if should_apply_op >= 1.0:
        augmented_image = func(image, *args)
        return augmented_image, func
    else:
        augmented_image = image
        return augmented_image, None