In the game , we use a method called color picker to select units.
This means that each visible device is assigned a unique color.
Here is an example of a scene made to select a color:

Since some users may have 16-bit displays, these colors may be in the range of 0..64K.
However, if we give the units incremental colors, for example. unit0 is 0, unitN is N, then the colors are very difficult to debug people. Units are almost indistinguishable.
We want to give units unique and distinctive colors.
We are currently increasing the fixed pitch using a binary tree (C ++ map ) to store the colors used to check for conflicts. This is a low level hardware performance issue. Even if it was a hash table and avoiding the use of string , it is necessary to limit the temporary allocation of memory in game frames. Therefore, instead of optimizing the code in its current form, I really want to find out if there are ways to avoid the full story.
Is there a way to iterate over 0..64K numbers in large increments or randomly, so that most of the 64K possible values ββare used and avoid using the history of colors already highlighted to avoid collisions?
(It is unlikely that there are more than 64K visible blocks on the screen that we do not need to process in this case!)
c ++ random
Will
source share