Numeric rand::distr

Rust rand crate has a distr module for distributions, both trait and impls that simplify random generation, like Alphabetic, Alphanumeric. It also includes a SampleString trait that gives us a sample_string fn on it's impl, for generating a sampling string of len n. So, if we want a random alphanumeric string we can just write: 1use rand::distr::{Alphanumeric, SampleString}; 2 3fn main() { 4 println!("{}", Alphanumeric.sample_string(&mut rand::rng(), 20)); 5} This is incredibly useful, but distr doesn't include a Numeric distribution; which you might say isn't needed, since you can: ...

November 7, 2025 · 3 min · Nevalicjus

Python Colors

Even though I don't like C's do everything yourself, I love to reinvent the wheel for minor things. This snippet I put here for myself, but you're encouraged to use it. The loop below the class is to make Colors's be at the same time non-instantiated and have all the colors dynamically assigned from the dictionary. Colors.color-lowercase are methods for wrapping a string as color + string + reset, and Colors.color-uppercase are corresponding color codes as strings. ...

January 22, 2025 · 1 min · Nevalicjus