• CHANGELOG.md
• Example
• Installing
• Versions
• new51

# dart_random_choice #

A library for generating a random choice from an iterable.

## Example #

``````import 'dart:math' show Point;
import 'package:dart_random_choice/dart_random_choice.dart';

void main() {
const List<String> foodOptions = ['burger', 'pizza', 'salad'];
const List<double> weights = [10, 20, 0.4];
String whatToEat = randomChoice<String>(foodOptions, weights);
// I probably won't be eating a salad...

Set<Point> cardinalDirections = {
Point(0, 1), Point(0, -1),
Point(1, 0), Point(-1, 0),
};
Point direction = randomChoice<Point>(cardinalDirections);
// Each direction is equally likely.

Runes alphabet = Runes('abcdefghijklmnopqrstuvwxyz');
int charCode = randomChoice<int>(alphabet);
String char = String.fromCharCode(charCode);
// Any iterable works!
}
``````

## [0.0.1] - 03/28/2019

• Initial release.

example/main.dart

``````import 'dart:math' show Point;
import 'package:dart_random_choice/dart_random_choice.dart';

void main() {
const List<String> foodOptions = ['burger', 'pizza', 'salad'];
const List<double> weights = [10, 20, 0.4];
String whatToEat = randomChoice<String>(foodOptions, weights);
// I probably won't be eating a salad...
print('You should eat a \$whatToEat.');

Set<Point> cardinalDirections = {
Point(0, 1), Point(0, -1),
Point(1, 0), Point(-1, 0),
};
Point direction = randomChoice<Point>(cardinalDirections);
// Each direction is equally likely.
print('Move to \$direction.');

Runes alphabet = Runes('abcdefghijklmnopqrstuvwxyz');
int charCode = randomChoice<int>(alphabet);
String char = String.fromCharCode(charCode);
// Any iterable works!
print('\$char is my favorite letter.');
}
``````

## Use this package as a library

### 1. Depend on it

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

``````
dependencies:
dart_random_choice: ^0.0.2

``````

### 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_random_choice/dart_random_choice.dart';
``````
Version Uploaded Documentation Archive
0.0.2 Mar 29, 2019
0.0.1 Mar 29, 2019
 Popularity: Describes how popular the package is relative to other packages. [more] 6 Health: Code health derived from static analysis. [more] 100 Maintenance: Reflects how tidy and up-to-date the package is. [more] 88 Overall: Weighted score of the above. [more] 51

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

• Dart: 2.2.0
• pana: 0.12.14

#### Platforms

Detected platforms: Flutter, web, other

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

#### Health suggestions

Format `lib/dart_random_choice.dart`.

Run `dartfmt` to format `lib/dart_random_choice.dart`.

#### Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of `0.0.*`, it might mean that the author is still experimenting with the general direction of the API.

The package description is too short. (-2 points)

Add more detail to the `description` field of `pubspec.yaml`. Use 60 to 180 characters to describe the package, what it does, and its target use case.

#### Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.6.1