Function antithesis_sdk::random::random_choice

source ·
pub fn random_choice<T>(slice: &[T]) -> Option<&T>
Expand description

Returns a randomly chosen item from a list of options. You should not store this value, but should use it immediately.

This function is not purely for convenience. Signaling to the Antithesis platform that you intend to use a random value in a structured way enables it to provide more interesting choices over time.


use antithesis_sdk::random;

let choices: Vec<&str> = vec!["abc", "def", "xyz", "qrs"];
if let Some(s) = random::random_choice(choices.as_slice()) {
    println!("Choice: '{s}'");