Pick random element

import "std/random.zc"

fn main() {
    let rng = Random::new();
    let planets = ["Earth", "Venus", "Mercury", "Mars", "Jupiter"];
    // Permits repeats.
    for _ in 0..5 {
        let r = rng.next_int_range(0, 4);
        println "{planets[r]}";
    }
}

Output:

Sample output:

Mercury
Jupiter
Mercury
Mars
Venus

Attribution: This is a community solution for the Rosetta Code task Pick random element in Zen C.

This article uses material from the Rosetta Code article Pick random element, which is released under the GNU Free Documentation License 1.3. A list of the original authors can be found in the page history.