pub fn to_range(x: usize, a: usize, b: usize) -> usize
converts x into the range [a, b] in a pseudo-fair way.