Random select from a set of string values?

I am messing with some sets of neo pixel LED strings. I have the colors defind by their RGB values, I have RED, GREEN, YELLOW, BLUE, PURPLE, & ORANGE. I randomly select an LED# to assign a color to, but want to randomly pick from the colors listed above too. I cant figure that part out. Coworker said something like:

std::string Colors[6] = {“BLUE”,“GREEN”,“RED”,“YELLOW”,“ORANGE”,“PURPLE”};
int randomIndex = rand() % 3;
cout << "Random_Color " << Colors[randomIndex];

But I cant get it to work.

Any suggestions?

THanks

How about this,

char* colors[6] = {"BLUE","GREEN","RED","YELLOW","ORANGE","PURPLE"};

void setup() {
    Serial.begin();
}

void loop() {
    
    int randomIndex = rand() % 6;
    Serial.printf("%s ", colors[randomIndex]);
    delay(1000);
}
2 Likes

I’ll try it, thanks.