generate a random uuid in rust

To generate a random UUID in Rust, you can use the uuid crate. This crate provides a Uuid::new_v4() function that returns a random UUID v4.

Here is an example code snippet:

main.rs
use uuid::Uuid;

fn main() {
    let uuid = Uuid::new_v4();
    println!("{}", uuid);
}
88 chars
7 lines

This will print a random UUID v4, which looks something like this:

main.rs
f1eadad1-a86f-4d72-b880-e4d4e8b62c28
37 chars
2 lines

UUIDs generated with the v4 algorithm are unique with an astronomically high probability, making them a great choice for generating unique identifiers in your Rust programs.

gistlibby LogSnag