Palettes are not entirely random, but are either generated broadly according to a colour scheme, or a "theme" that's a lot more restrictive about what colours can show up.
Colours are manipulated in HSL rather than RGB. This isn't a perfect solution for hue rotation due to differences in chroma, but it's a start...
I will describe these in greater depth later...