Counting how many times each LED has turned on

I have a function that turns on a random LED out of 8 based on randomly generated number in the range of 256. I need to count how many times each LED has turned on and use this number to turn on each LED as many times as it was turned on randomly. I am using for loop to run it 100 times.

for (int i = 0; i < 100; ++i)
	{
		randomLED();
	}

And my function is:

void randomLED()
{
	
	int index;
		
	index = random(256);
	int index;
	int del3 = 100;
		
	
	
		if (index <= 31)
		{
			digitalWrite(ledPins[0], HIGH);
			delay(del3);
			digitalWrite(ledPins[0], LOW);


		}
		else if (index >= 32 && index <= 63)
		{
			digitalWrite(ledPins[1], HIGH);
			delay(del3);
			digitalWrite(ledPins[1], LOW);


		}

		else if (index >= 64 && index <= 95)
		{
			digitalWrite(ledPins[2], HIGH);
			delay(del3);
			digitalWrite(ledPins[2], LOW);


		}
		else if (index >= 96 && index <= 127)
		{
			digitalWrite(ledPins[3], HIGH);
			delay(del3);
			digitalWrite(ledPins[3], LOW);


		}
		else if (index >= 128 && index <= 159)
		{
			digitalWrite(ledPins[4], HIGH);
			delay(del3);
			digitalWrite(ledPins[4], LOW);


		}
		else if (index >= 160 && index <= 191)
		{
			digitalWrite(ledPins[5], HIGH);
			delay(del3);
			digitalWrite(ledPins[5], LOW);


		}
		else if (index >= 192 && index <= 223)
		{
			digitalWrite(ledPins[6], HIGH);
			delay(del3);
			digitalWrite(ledPins[6], LOW);


		}
		else if (index >= 224 && index <= 256)
		{

		
			digitalWrite(ledPins[7], HIGH);
			delay(del3);
			digitalWrite(ledPins[7], LOW);

			
		}


		delay(del3);
		randomSeed(analogRead(1));
	

}
  int index;
  index = random(256);
  int index;

How many variables called index do you want?

I had a problem with my index because I did not define it in correct function. I changed it:

	int index = random(256);

	
	int del3 = 100

I am just trying to understand how can I make the function return a value for each time it runs and then store it until it is not executed 100 times.

randomLED is a void function; it can’t return a value.
Maybe fix that first.

When you get around to posting again, please don't cut up your program, paste the complete sketch.

goldencaravan:
I need to count how many times each LED has turned on and use this number to turn on each LED as many times as it was turned on randomly.

If the same LED is on twice in succession does that count as one or two turn-ons?

I need to count how many times each LED

you have already an array for your led pins.
So add an additional array for your counters:

byte ledCounter[8];

and increase the counter when you switch on the led

ledCounter*++;*