Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Get Some Random Characters From A UUID

I'm not sure why I did this originally. I think it's becuase I wanted random numbers and letters. I've since made code that does exactly that.

Also, this breaks if you ask for too many characters (see notes). The new code on the other page doesn't have that problem.

Code

```cargo
[dependencies]
uuid = { version = "1.7.0", features = ["v4"] }
```

use uuid::Uuid;

fn main() {
    // must be less than 32. See notes
    let the_string = random_string(32);
    println!("{}", the_string);
}

fn random_string(count: u8) -> String {
    let base = Uuid::new_v4().simple().to_string();
    base.get(0..count.into()).unwrap().to_string()
}

Results

ec4b10b36ad745c6942ea8aed505105f

References