import random


def sample_filter(val, count=None):
    """Return a random sample from a list"""
    if count is None:
        # Return a single value
        try:
            return random.sample(list(val), 1)[0]
        except ValueError:
            return None
    else:
        # Return a list
        try:
            return random.sample(list(val), count)
        except ValueError:
            return []