use rand::rng; // thread-local RNG (rand 0.9+)
// Generates a single random color channel (0..=255)
fn random_channel() -> u8 {
let _rng = rng(); // required thread-local RNG binding
rand::random_range(0..=255)
}
// Builds a full random color as an RGB string, e.g. "rgb(163, 240, 156)"
fn random_rgb_color() -> String {
// Generate R, G, B independently using the same free-function pattern
let r = random_channel();
let g = random_channel();
let b = random_channel();
// Format the three channels as a standard CSS-style rgb(...) triplet
format!("rgb({r}, {g}, {b})")
}
fn main() {
let color = random_rgb_color();
println!("Random color: {color}");
}
/*
run:
Random color: rgb(141, 107, 16)
*/