I need a function which will generate three numbers so I can use them as RGB pattern for my SVG.
While this is simple, I also need to make sure I'm not using the same color twice.
How exactly do I do that? Generate one number at a time with simple rand
(seed time active) and then what? I don't want to exclude a number, but maybe the whole pattern?
I'm kind of lost here.
To be precise, by first calling of this function I will get for example 218 199 154 and by second I'll get 47 212 236 which definitely are two different colors. Any suggestions?
Also I think a struct
with int r, int g, int b
would be suitable for this?
Edit: Colors should be different to the human eye. Sorry for not mentioning this earlier.
You could use a set to store the generated colors. First instanciate a new set. Then, every time you generate a color, look if the value is present in your set. If the record exists, skip it and retry for a new colour. If not, you can use it but dont forget to cache it in the Set after. This may become not performant if you need to generate a big quantity of colour.