INNER CODE UNIT · Python

_infinite_stream

webartifex/intro-to-python · 08_mfr/stream.py:20

def _infinite_stream():
    """Internal generator function to simulate an infinite stream of data."""
    while True:
        number = max(0, int(_random.gauss(42, 8)))
        if _random.randint(1, 100) == 1:
            number *= 2
        yield number


def make_finite_stream(min_=5, max_=15):
    """Simulate a finite stream of data.

    The returned stream is finite, but the number of elements to be produced
    by it is still random. This default behavior may be turned off by passing
    in `min_` and `max_` arguments with `min_ == max_`.

    Args:
        min_ (optional, int): minimum numbers in the stream; defaults to 5

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…