#iterator #min-max #random #max #min

no-std kindness

Methods for returning random elements from an iterator

4 releases (breaking)

0.5.0 Feb 7, 2025
0.4.0 Dec 12, 2022
0.3.0 Nov 17, 2022
0.2.0 Nov 16, 2022

#1002 in Algorithms

Download history 14/week @ 2024-10-29 6/week @ 2024-11-05 12/week @ 2024-12-10 125/week @ 2025-02-04 5/week @ 2025-02-11

130 downloads per month

MIT license

52KB
1K SLoC

kindness

GITHUB Crates.io GitHub Workflow Status docs

Methods for choosing random elements from an iterator.

Includes choose_item(), choose_max(), choose_max_by(), choose_max_by_key(), choose_min(), choose_min_by(), choose_min_by_key()

no_std by default. The std feature unlocks the choose_unique() and choose_unique_by_key() methods.

The name of the crate is a pun. "Random max of kindness". I'm sorry.


This crate works with Cargo with a Cargo.toml like:

[dependencies]
kindness = "0.5.0"
rand = "0.9.0"

Getting started

use kindness::*;
use rand::SeedableRng;

fn main() {
    let mut rng = rand::rngs::StdRng::seed_from_u64(123);
    let m =[3,2,1,2,3].iter().choose_max(&mut rng).unwrap();
    assert_eq!(*m, 3)
}

Contributing

Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change.

Check out the Contributing section in the docs for more info.

License

This project is proudly licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT).

kindness can be distributed according to the MIT license. Contributions will be accepted under the same license.

Authors

Dependencies

~1.5MB
~21K SLoC