Infinite random set generator


This example was created to show that iterators (generators) don't necessarily return a fixed list of values.


examples/generators/random_set_generator.py
import random

def choices(values, **kw):
    while True:
        yield random.choices(values, **kw)

count = 0
for val in choices(['a', 'b', 'c', 'd', 'e', 'f'], k=2):
    print(val)
    count += 1
    if count > 10:
        break