import random


def subsample_array(arr, max_values, can_modify_incoming_array=True, rand=None):
    """Shuffles the array and returns `max_values` number of elements."""

    if not can_modify_incoming_array:
        arr = arr[:]
    if rand is not None:
        rand.shuffle(arr)
    else:
        random.shuffle(arr)
    return arr[:max_values]