I wrote a utility function once to do this.
The idea was to linearize the RGB space in the 1D [0, 1] interval. For example, execute (R + G * 256 + B * 256 * 256) / (256 ^ 3 * 256 ^ 2 + 256).
Then, every time you need a new color, you separate the interval generated by the previous selections in 2. You select the first color as 0.0 in the new space, the second as 1.0, the third as 0.5, then 0.25, then 0.75 and so on. This view ensures that if you create multiple colors, they have maximum โseparationโ (although they are not measured in terms of hue). As you generate more and more colors, they usually come close to the one created earlier, but always observe the principle of maximum separation.
Once you have the value [0, 1], you use the inverse function (the triplet of functions actually) to return to RGB.
In the base implementation, you get white and black as the first two colors. If you want something else, once you have generated your "input" value [0, 1], you can rotate it, say, third, within the same interval.
This works very well and behaves deterministically (without an unlimited number of attempts).
source share