problems with 595 shift registers

hello everybody
I’m trying to use 2 74HC595 to power 16 leds. I never had any problem with those shift registers, but now using this code:

while(1) {    
   for(int i=0; i<8; i++) {
        digitalWrite(ledL, LOW);
        shiftOut(ledD, ledC, LSBFIRST, B00000001<<i);
        shiftOut(ledD, ledC, LSBFIRST, B00000001<<i);
        digitalWrite(ledL, HIGH);

it works ok for some time (it cycles through the leds, example: led 1 and led 9 on, the other off, then led 2 and led 10 on, and so on…)
but then suddenly, leds light up at random for some time.
I’ve used 0,1 cap on power pins of each 595 chip…
what could be the problem?
it should not be a code problem…since it works ok for some cycles…

I don't think the problem is the software.

Bad wires? Bad breadboard connection? Need more capacitors?

fixed it, the problem was that arduino was using USB supply while 595 a different 5V supply

Did you have the grounds between the 2 supplies connected?

no, thery were totally separated, arduino powered from USB, the registers from a power supply..the only connections were the 3 digital lines (clock, data and latch)

That would do it then - connecting the Gnds from the various supplies is needed.