Here is an easy way:
1.Generate a random integer. 2.Shift it 8 times to have 24 meaningful bits, store this integer value. 3.Use first 8 bits for R, second group of 8 bits for G, and the remaining 8 bits for B value.
For each new random number, shift it 8 times, compare all the other integer values that you saved earlier, if none of them matches the new one, use it for the new color (step3).
The differentiation of the human eye is an interesting topic, as thresholds of perception vary from one person to another. To achieve this, change the integer 14 times, get the first 6 bits for R (two bytes to two to get 8 bits again), get the second 6 bits for G and the last 6 bits for B. If you think that 6 bits are not are good for him, reduce him to 5.4 ...
A simple run with 4 significant bits for each channel: My random integer:
0101-1111-0000-1111-0000-1100-1101-0000
I shift (you can also use multiply or modulo) so that it leaves 20 times:
0000-0000-0000-0000-0000-0101-1111-0000
save this value.
Then get the first 4 bits for R, the second 4 bits for G and the last 4 bits for B:
R: 0101 G: 1111 B: 0000
Place them so that each of them consists of 8 bits.
R: 0101-0000 G: 1111-0000 B: 0000-0000
Use them for your color components.
For each new random number after the offset, compare it with your stored integer values. If it is different, save and use it for color.