import torch


def rand_select(tensor, exclude=None, do_squeeze=True):
    """ Randomly selects one item from the given tensor
    """
    index = torch.randint(tensor.size()[0], (1, 1))
    selection = tensor[index]

    # If we want to exclude certain values, grab a different one (rolls backwards)
    if exclude is not None:
        selection = tensor[index - 1]

    if do_squeeze:
        return selection.squeeze()
    else:
        return selection