(seq, n, stratify=True, random_state=None)
Args:
        seq (Sequence)
        n (int)
        stratify (bool)
        random_state (int)

    Returns:
        list
Args:
        seq (Sequence)
        n (int)
        stratify (bool)
        random_state (int)
Args : seq ( Sequence ) n ( int ) stratify ( bool ) random_state ( int )
def get_random_sample(seq, n, stratify=True, random_state=None):
    """
    Args:
        seq (Sequence)
        n (int)
        stratify (bool)
        random_state (int)

    Returns:
        list
    """
    random.seed(a=random_state)
    if stratify is True:
        grped = itertoolz.groupby(operator.itemgetter(1), seq)
        n_per_grp = max(int(round(n / len(grped))), 1)
        sample = list(
            itertoolz.concat(
                random.sample(examples, min(len(examples), n_per_grp))
                for examples in grped.values()
            )
        )
        random.shuffle(sample)
        return sample[:n]
    else:
        return random.sample(seq, min(len(seq), n))
def get_random_sample ( seq , n , stratify = True , random_state = None ) : random . seed ( a = random_state ) if stratify is True : grped = itertoolz . groupby ( operator . itemgetter ( 1 ) , seq ) n_per_grp = max ( int ( round ( n / len ( grped ) ) ) , 1 ) sample = list ( itertoolz . concat ( random . sample ( examples , min ( len ( examples ) , n_per_grp ) ) for examples in grped . values ( ) ) ) random . shuffle ( sample ) return sample [ : n ] else : return random . sample ( seq , min ( len ( seq ) , n ) )