Simple LEDs and Serial sketch - weird bug?

I'm a newbie with arduino, but slightly more experienced with programming and circuits.

I was trying a simple program -
9 LEDs connected to 9 output pins (2-10), each connected in series a to 330ohm resistor.
The sketch selects 2 random pins, and causes the corresponding LEDs to blink twice.

The program worked great.

I then added a serial communication to see in the monitor what pins are selected (I basically added a println to print values of integers i and j):
Program goes crazy. LEDs stop behaving as before.

what am I missing?!
(see attached ino file)

Thanks.

Leds_and_Serial.ino (870 Bytes)

Easy, when you print the values, you have the following syntax:

Serial.println(i,j);

It should be:

Serial.print(i);
Serial.print(", ");
Serial.println(j);

That should fix it.

Also, I don't know if this changes anything, but you don't set a seed for the random function.

See:

https://www.arduino.cc/en/Reference/RandomSeed

  i,j=random(0,9);                // generate 2 random numbers between 0 and 8, to select 2 pins

That is NOT what that code does. Only Kernighan and Ritchie are allowed to invent syntax. The rest of us have to use what they invented.

Thanks Everyone. It works OK now.

BTW, PaulS, I never said I wasn't Kernighan or Ritchie..... Obiously Joker54 is not my legal name.

I never said I wasn't Kernighan or Ritchie.

I'm Spartacus !