Siile/Ninslash

Random colors (AI)

Siile opened this issue · 2 comments

Siile commented

Now I use m_TeeInfos.m_ColorBody = rand()*(0xFFFFFF/RAND_MAX); to generate random color for bots. This works fine with windows, but results in 0 (dark gray) on unix machines. Suggestions for a fix?

The explanation for why you get a result of zero there is fairly easy: I don't know what value RAND_MAX has on Windows, but on my Linux machine it's 0x7FFFFFFF. Now you may already see what's wrong: dividing 0xFFFFFF by 0x7FFFFFFF (decimal: 16777215÷2147483647) results in 0.0078125, which is being truncated to 0 since you're working with integers.

For the colors you need a value between 0x000000 and 0xFFFFFF, right? For that I'd suggest rand()%(0xFFFFFF+1) (so rand()%1000000)

Siile commented

Works well enough now. :)