Erratic Behavior MAX7219

I wrote a simple program using the ledControl library to scroll through 0-9 on digit 0 of a 3 digit 7 segment display. It sometimes works the first time through, and after that some numbers start appearing on other digits, and numbers are being skipped. Other times it just stops all together.

Here is my code

#include "LedControl.h"

LedControl lc=LedControl(12,11,10,1);

unsigned long delaytime=250;

void setup() {
  
  lc.shutdown(0,false);
  lc.setIntensity(0,8);
  lc.setScanLimit(0,3);
  lc.clearDisplay(0);
}

void loop() {
  for(int i=0;i<10;i++){
    lc.setDigit(0,0,i,false);
    delay(1000);
    lc.clearDisplay(0);
    delay(100);
  }
}

The displays are common cathode.
I have checked the wiring to the max7219, and i know it works because the right numbers are being displayed some of the time.
I have used different resistances between Rset and V+
I have tried different max7219 chips.

Try Nick Gammons circuit.

Erratic behavoure always equals lack of decoupling capacitors.

The capacitors solved the problem. Thank you.