SSampleThicket
Product

Product features · Stream reservoir sampling

01

Use SampleThicket to distinguish the retained reservoir from the input stream already consumed.

01

Connection

Base URL, credentials and a reachable server.

02

Selection

A model available through the configured endpoint.

03

Capabilities

Context limits and tool support are determined by the model and server.

Stream reservoir sampling

● ● ●SampleThicket●
A concrete starting point · Stream reservoir sampling ×
from random import Random

def reservoir_sample(items, size, seed):
    if type(size) is not int or not 0 <= size <= 32:
        raise ValueError("size.range")
    if type(seed) is not int or not 0 <= seed < 2**32:
        raise ValueError("seed.range")
    rng, sample, count = Random(seed), [], 0
    for index, item in enumerate(items):
        count = index + 1
        if count > 1000:
            raise ValueError("stream.limit")
        if index < size:
            sample.append(item)
        elif size:
            position = rng.randrange(count)
            if position < size:
                sample[position] = item
    if size > count:
        raise ValueError("stream.short")
    return sample
✳Select a reservoir of at most 32 items from a finite stream of at most 1000 items using a local seeded generator.
✓ ChangesReview before applying ↗
Illustrative workspace
AI coding workspace

Your next change starts here.

Get the Windows app ↗