dart_collection_sampler 0.5.1

  • README.md
  • Installing
  • Versions
  • 49


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.



  • 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.5.1"

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.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


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

  • Dart: 2.0.0-dev.60.0
  • pana: 0.11.3


Describes how popular the package is relative to other packages. [more]
0 / 100
Code health derived from static analysis. [more]
97 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter, web, other

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


  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 3 hints.

    Run dartfmt to format lib/dart_collection_sampler.dart.

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

    Similar analysis of the following files failed:

    • lib/src/dice_sampler.dart (hint)
  • 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.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0
dart_dice_parser >=0.1.1 <2.0.0 0.1.2
Transitive dependencies
matcher 0.12.2+1
path 1.6.0
petitparser 1.7.6
stack_trace 1.9.2
Dev dependencies
args >=0.13.4 <2.0.0
mockito 2.2.0
test ^0.12.0