def inverse_transform_sampling(cdf, x_values, num_samples=1):
    """
    Performs inverse transform sampling given a CDF.
    Used for sampling audio prompt lengths in ICL mode.
    """
    # Generate uniformly distributed random numbers
    r = np.random.rand(num_samples)
    # Find corresponding x values using interpolation on the CDF
    random_samples = np.interp(r, cdf, x_values)
    return random_samples

    Performs inverse transform sampling given a CDF.
    Used for sampling audio prompt lengths in ICL mode.
    
finetune/core/preprocess_data_conditional_xcodec_segment.py