If you're just trying to get a random index value for the colors array, you simply do that first:
PHP Code:
new iRandomIndex = random(sizeof(g_fColors))
Then, you can choose to use that or whatever settings you have.
PHP Code:
new ActualColorIndex = (setting == -1 ? iRandomIndex : setting)
then use this index for g_fColor:
PHP Code:
new red = g_fColor[ActualColorIndex][0]
new green = g_fColor[ActualColorIndex][1]
new blue = g_fColor[ActualColorIndex][2]
If you want each component of the color to be independently random then you need to do the same thing for each of the three components.
I think you're complicating things by trying to be clever with your code. Stop using the preprocessor and write basic code first, it doesn't have to be pretty or scalable, just write it to make it work. Get that working and then optimize later.
Quote:
Originally Posted by lexzor
since the value of g_fColors is hardcorded, you could return the index of the colors by using random(sizeof(g_fColors)-1)
|
The function "random" is designed specifically for indexing arrays based on the size of the array so you should not subtract 1 unless you're intentionally trying to exclude the last value in the array.
__________________