Sha256: f88e0ee47876620edc3bc04c8f11a8e381dc55b1e1892dc3742c311dc05c1d98

Contents?: true

Size: 667 Bytes

Versions: 2

Compression:

Stored size: 667 Bytes

Contents

# StreamSampler - a gem to add stream sampling to Ruby classes.

This gem adds stream sampling (aka reservoir sampling) to Ruby. To use,
add the gem to your Gemfile (or require it explicitly), and call the
`StreamSampler.reservoir_sample` method:

    require 'stream_sampler`
    # takes a 10 item sample from a stream of items:
    items = (1..1000).to_a
    StreamSampler.reservoir_sample(items, 10)

As a special case, if ActiveRecord and ActiveSupport are defined, the stream
sampling methods will be added as class methods on `ActiveRecord::Base`, so you
can do things like this:

    require 'stream_sampler'
    User.where(age: (18..65)).reservoir_sample(10)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stream_sampler-0.0.2 README.md
stream_sampler-0.0.1 README.md