Pseudo pseudorandom color picker

This commit is contained in:
Alexey 2025-09-18 16:30:37 +03:00
commit 218ee49a8b
7 changed files with 75 additions and 15 deletions

View file

@ -1,5 +1,5 @@
use config::Config;
use std::path::PathBuf;
use std::{hash::{DefaultHasher, Hash, Hasher}, path::PathBuf};
pub mod config;
pub mod log;
@ -13,3 +13,11 @@ pub fn load_config() -> Config {
}
Config::new(PathBuf::from("./config.toml"))
}
/// Get random-like color id in range 0..16 by computing string hash
pub fn color_id_from_name(name: String) -> i32 {
let mut s = DefaultHasher::new();
name.hash(&mut s);
let hash = s.finish();
(hash.count_ones() / 4) as i32
}