random function not working as expected. [solved]

I’m trying to create a random function to light some LEDs. The code in question is below. My issue is when I tell random I want a number 1-6 which I thought was inclusive doesn’t ever pick 1. In 3 attempts 200 tries each I would think it would have picked it. I’ve also tried it without the “1,” and with “0”, by neither worked. I can post the full code if needed it’s only 80 lines. Thanks in advance.

for (int i=0; i <=200; i++){ // Run Random
ranNum=random(1,6); // Pick random pin
digitalWrite(ranNum, HIGH); // energizes
delay(50); // wait
digitalWrite(ranNum, LOW); // de-energizes
} // END FOR

if you're talking about an Arduino Uno, pin 1 is the transmit data pin, called "TXD." From the ATmega328 datasheet, dated 02/2013, paragraph 20.6: "When the Transmitter is enabled, the normal port operation of the TxDn pin is overridden by the USART ..." It'll probably work if you don't execute a Serial.begin() statement, or after you execute a Serial.end().

If you want to see random(1,6) picking 1 a few times, try Serial.print(random(1,6)) a bunch of times. I think that you'll see some 1's in the output.

tmd3: if you're talking about an Arduino Uno, pin 1 is the transmit data pin, called "TXD." From the ATmega328 datasheet, dated 02/2013, paragraph 20.6: "When the Transmitter is enabled, the normal port operation of the TxDn pin is overridden by the USART ..." It'll probably work if you don't execute a Serial.begin() statement, or after you execute a Serial.end().

If you want to see random(1,6) picking 1 a few times, try Serial.print(random(1,6)) a bunch of times. I think that you'll see some 1's in the output.

Interesting, the pin does work in the early portions of the code where I call it directly. And I am not using the serial calls. It's an Arduino Duemilenove ATmega328. This section does work as expected. digitalWrite(relayPin1, HIGH); // energizes digitalWrite(relayPin3, HIGH); // energizes digitalWrite(relayPin5, HIGH); // energizes delay(250); // wait digitalWrite(relayPin1, LOW); // de-energizes digitalWrite(relayPin3, LOW); // de-energizes digitalWrite(relayPin5, LOW); // de-energizes

Wow, I’m just a newb. I wired the relay pack backward. It actually wasn’t firing pin 6. Changing it to ranNum=random(1,7); did the trick. Thanks for the input I figured it out while trying to do your serial suggestion.