I have a long python generator that I want to \"thin out\" by randomly selecting a subset of values. Unfortunately, random.sample() will not work with arbitrary
random.sample()
Use the itertools.compress() function, with a random selector function:
itertools.compress()
itertools.compress(long_sequence, (random.randint(0, 100) < 10 for x in itertools.repeat(1)))