dart_random_choice
0.2.0, released 4 years ago by kirocodes.dev
Select a random element from any iterable, optionally using weights.
What it does
The package exposes a generic randomChoice<T> function that returns a randomly selected item from an iterable. You can provide a parallel list of numeric weights to bias the selection.
AI-written summary of version 0.2.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need a quick, dependency‑free way to pick a random item from a list or set
- You want weighted random selection without pulling in larger libraries
Skip it when
- Cryptographically secure randomness is required
- You need asynchronous streams or reactive selection
Strengths
- Zero external dependencies
- Null‑safe and works on all Dart platforms
- Supports weighted selection
Weaknesses
- Uses dart:math random, not suitable for security‑critical use
- No async or stream support
- Limited to simple weight lists
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
import 'package:dart_random_choice/dart_random_choice.dart';
void main() {
const foods = ['burger','pizza','salad'];
const weights = [10,20,0.4];
var choice = randomChoice<String>(foods, weights);
print(choice);
}Alternatives
Packages that do the same job and could replace dart_random_choice.
- word_generator
A Dart utility package for generating random words, names, usernames, and passwords.
73Compare - random_user_agents
Generate random User-Agent strings for Dart/Flutter apps
72Compare - random_string
Generates random ASCII strings, numbers, and alphanumeric sequences for testing purposes.
50Compare - username_generator
A Dart library that creates random or seedable usernames for emails and user forms.
46Compare