Trying to retrieve a number in string and use it as index for an array of pinled

Hi! First of all thanks in advance for reading.
I'm taking first steps with Arduino. I'm trying to make a Simon Game (Please if it this already exist don't send me a link. i'm tryint to do it by my self).

To add new pin colors after succesful tries i've created a String to enlarge the led order. I choose string type because .charAt() function.

This is the relevant part of the code

int led[] = {9, 8, 7, 6}; 
int buttonPressed[4];
String randomStep; //string para manejar los random
unsigned int lastStep = 0;

void setup() {
   Serial.begin(9600);
  //Setup the LED :
  for (int i = 0; i < (sizeof(led)/sizeof(int)); i++) {
    pinMode(led[i], OUTPUT);
  }
  randomSeed(analogRead(0));
}

void loop() {
  if (randomStep.length() == 0) {
      // Startup Code //
  }
  if (randomStep.length() != lastStep) {

      // [+++ here goes code with buttons ++++ Succesful attemp would increment lastStep
          lastStep++;
          
      }
  }
 

 } else { 
      //So here are my issues!!!
      randomStep = randomStep + String(random(0,4));
      for (int i=0; i < randomStep.length(); i++) {
        int currentLed;
        currentLed = (int)randomStep.charAt(i);
        Serial.print(led[(char)currentLed]);
        //if I send the variable to Serial it shows me 0, 1 2 or 3 which are the possible numbers
        // but when I'm trying to get the ledPIN from led[] array, serial monitor shows me 14891 or 29281 (depending of value) 
       //I tried with (int) (long)
       // using atoi always give me 0.
        digitalWrite(led[currentLed],HIGH);
        delay(500);
        digitalWrite(led[currentLed],LOW);
        delay(500);
      }
  
 }

}

What do I need to do to get the correct type to pass it to array as an array Index? Is there a better way to do this?

Please forgive my writing.
I'm not very sure if i'm explaining myself. English is not easy for me.

Regards
Rodrigo de los Santos

Finally i've managed throug a switch/case... I don't know if i'm reinventing the wheel with this. In my country it could be called "Una Grasada" but it worked for me.

...
        int currentLed;
        currentLed = randomStep.charAt(i);
        int selectedLed;
          switch (currentLed) {
            case 48:
            selectedLed = 0;
            break;
            case 49:
            selectedLed = 1;
            break;
            case 50:
            selectedLed = 2;
            break;
            case 51:
            selectedLed = 3;
            break;
            default:
          }

        digitalWrite(led[selectedLed],HIGH);
        delay(500);
        digitalWrite(led[selectedLed],LOW);
        delay(500);
...

I suppose there are another, more easy to do.
Regards

I suppose there are another, more easy to do.

Leaving aside the unnecessary use of Strings for now, in your switch/case do you see the consistent relationship between the value of currentLed and selectedLed ? Subtract 48 from currentLed and what number do you get ?

int currentLed= randomStep.charAt(i);
int selectedLed = currentLed - '0';