Are you sure that the bug is with the buttons drawing?
Looks like you're generating a random number between 1 and 3, then using that as an index into an array of colors. You have a 33% chance of getting yellow
every time. Same with red and blue. So it's not surprising to see that the buttons occasionally get the same colors.
Said another way...the colors are changing, you just don't see when they change from Yellow to Yellow.
What about a different approach? You could have an array of brushes that you just cycle through. Rather than picking random numbers, you could pick a random
offset and use
%, the modulus operator[
^] to help grab the 'new' brush color.
Sorry if I'm not reading your code correctly...if this doesn't appear to be the case, perhaps attach a debugger to your code, set some break points and even some logging to see what the old color and new color were and are.
Hope this helps some.
Cheers.