Closed jc00ke closed 1 year ago
I happened to see your post on Hachyderm and thought it would be fun on a Sunday to add random separators. This is my first Rust contribution, so if you have any feedback, I'm all ears!
I first went down the path of adding a new flag like -r
but I thought it would end up being more changes and kinda weird. I'm not in love with the _*
format, but thought it was a good place to start.
ooo elegant. Thanks so much!
One note for ya: This line Uniform::from(0..9).sample(rng).to_string()
returns 0 through 9 exclusive, meaning it will never return 9
, just 0 through 8.
You could make it inclusive with an =
: Uniform::from(0..=9).sample(rng).to_string()
.
Though I'm going to use get_range()
for now:
fn get_random_number(rng: &mut impl Rng) -> String {
rng.gen_range(0..=9).to_string()
}
From the gen_range()
docs:
This function is optimised for the case that only a single sample is made from the given range. See also the Uniform distribution type which may be faster if sampling from the same range repeatedly.
Oops, I didn't realize it was exclusive, good catch. gen_range
looks good for this too.
This adds special
-s
values that will generate random values.