1
0
Fork
You've already forked random_item
0
A Cargo crate which allows retrieving a random item out of a sequential collection. https://crates.io/crates/random_item
  • Rust 100%
2026年01月15日 00:53:09 -06:00
src refactor: duplicate logic 2025年06月08日 00:12:51 -05:00
.gitignore Initial Commit 2025年06月07日 01:23:29 -05:00
Cargo.lock feat: fix readme documentation error 2026年01月15日 00:53:09 -06:00
Cargo.toml feat: fix readme documentation error 2026年01月15日 00:53:09 -06:00
README.md feat: fix readme documentation error 2026年01月15日 00:53:09 -06:00

Random Item

Get a random item out of a sequential collection.

Getting A Reference

userandom_item::random_item;letmessages=Vec::from([String::from("Hello, "),String::from("fellow "),String::from("Rustaceans!"),]);letrandom_message=random_item(&messages);

Getting An Owned Value (Cloned)

userandom_item::random_owned_item;#[derive(PartialEq, Clone)]struct Shape{sides: u32,}letshapes=[Shape{sides: 1},Shape{sides: 1},Shape{sides: 2},Shape{sides: 3},Shape{sides: 5},Shape{sides: 8},Shape{sides: 13},Shape{sides: 21},];letrandom_shape=random_owned_item(&shapes);