dart_collection_sampler 0.6.0

  • README.md
  • Installing
  • Versions
  • 50


a small library implementing methods to sample items from collections


A simple usage example:

import 'package:args/args.dart';

import 'dart:io';
import 'package:dart_collection_sampler/dart_collection_sampler.dart';

main(List<String> arguments) {

  var argParser = new ArgParser()
      ..addOption("num", abbr: "n", help: "items to pick from rest of command line", defaultsTo: "1");
  var results = argParser.parse(arguments);

    roll(int.parse(results["num"]), results.rest)

int roll(int n, List<String> items) {
  if (items.isEmpty) {
    print ("you must supply one or more items as input");
    return 1;
  print ("Picking $n from $items\n");

  if (n == 1) {
    print ("Selected item: ${new CollectionSampler().pick(items)}");
  } else {
    print ("Selected items: ${new CollectionSampler().pickN(items, n)}");
  return 0;

Features and bugs

Please file feature requests and bugs at the issue tracker.



update to dart 2


  • fix problem introduced by 0.5.0 changes for fixed-length reservoir


  • initialize reservoir size
  • clarify some details of reservoir sampling algorithm in method doc


  • clarify which selection methods return unique and non-unique


  • fix dumb comment in example


  • clean up all samplers to use reservoir sampling
  • add example code


  • fix up interfaces to use List, implement ReservoirSampler


  • Initial version, created by Steve Christensen

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  dart_collection_sampler: ^0.6.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:dart_collection_sampler/dart_collection_sampler.dart';
Version Uploaded Documentation Archive
0.6.0 Oct 3, 2018 Go to the documentation of dart_collection_sampler 0.6.0 Download dart_collection_sampler 0.6.0 archive
0.5.1 Dec 10, 2017 Go to the documentation of dart_collection_sampler 0.5.1 Download dart_collection_sampler 0.5.1 archive
0.5.0 Dec 9, 2017 Go to the documentation of dart_collection_sampler 0.5.0 Download dart_collection_sampler 0.5.0 archive
0.4.0 Dec 8, 2017 Go to the documentation of dart_collection_sampler 0.4.0 Download dart_collection_sampler 0.4.0 archive
0.3.0 Dec 2, 2017 Go to the documentation of dart_collection_sampler 0.3.0 Download dart_collection_sampler 0.3.0 archive
0.2.0 Dec 2, 2017 Go to the documentation of dart_collection_sampler 0.2.0 Download dart_collection_sampler 0.2.0 archive
0.1.0 Dec 2, 2017 Go to the documentation of dart_collection_sampler 0.1.0 Download dart_collection_sampler 0.1.0 archive
0.0.2 Dec 2, 2017 Go to the documentation of dart_collection_sampler 0.0.2 Download dart_collection_sampler 0.0.2 archive
0.0.1 Dec 1, 2017 Go to the documentation of dart_collection_sampler 0.0.1 Download dart_collection_sampler 0.0.1 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:dart_collection_sampler/dart_collection_sampler.dart.

Health suggestions

Format lib/dart_collection_sampler.dart.

Run dartfmt to format lib/dart_collection_sampler.dart.

Format lib/src/collection_sampler.dart.

Run dartfmt to format lib/src/collection_sampler.dart.

Format lib/src/dice_sampler.dart.

Run dartfmt to format lib/src/dice_sampler.dart.

Maintenance suggestions

Maintain an example.

None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use dart_collection_sampler.dart. Packages with multiple examples should use example/readme.md.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
dart_dice_parser ^0.2.0 0.2.0
Transitive dependencies
petitparser 2.0.2
Dev dependencies
args ^1.5.0
mockito ^3.0.0
test ^1.3.4