import random


def randomize_dataset(dataset, start, end):
    """
    Randomly set the start and end of the dataset, in order to avoid the bias of always have 2 days at before and after the anomalies
    :param dataset: Anomaly dataframe
    :param start: timestamp
    :param end: timestamp
    :return: Randomized dataset
    """
    margin = 10
    before_length = dataset[dataset['timestamp2'] < start].shape[0]
    after_length = dataset[dataset['timestamp2'] > end].shape[0]
    before_clip = random.randint(0, before_length - margin)
    after_clip = random.randint(dataset.shape[0] - after_length, dataset.shape[0]) + margin
    return dataset[before_clip:after_clip]