I assume that you randomized in the RGB color space; if you use a different color space, for example. HSB, it is easier to determine if the two colors are similar, and you can limit the range of each axis to eliminate ugly colors.
For example, you can create the first color using:
- full range of shades
- full saturation (100%)
- brightness in the upper 50%
And then a contrasting color using:
- first color cast +/- certain random value
- full saturation (100%)
- brightness in the lower 50%, but maxing at a sufficient distance compared to the first color
The possibilities are endless, but the basic idea is that HSB is a more βnaturalβ color space for randomization, because you control the perceived color properties (hue, saturation, brightness) rather than technical properties (intensity from three channels).
source share