title: How can I randomly select an Arduino pin output?
body: <p>I have a series of eight LEDs that I'm trying to fade in and out randomly, starting from ON. Here's where I am so far.</p>
  
  <pre><code>#define LED1 2
  #define LED2 3
  #define LED3 4
  #define LED4 5
  #define LED5 6
  #define LED6 7
  #define LED7 8
  #define LED8 9
  
  void setup() {
  pinMode(LED1,output);
  pinMode(LED2,output);
  pinMode(LED3,output);
  pinMode(LED4,output);
  pinMode(LED5,output);
  pinMode(LED6,output);
  pinMode(LED7,output);
  pinMode(LED8,output);
  }
  
      void cycleLED() {
          timeOn = random(600,1800);
          timeOff = random(600,1800);
          for (fadeOut = 255; fadeOut &gt; 0; fadeOut--) { 
              analogWrite(LED, fadeout);
              delay(timeOff); 
          }
  
          for (fadeIn = 0;fadeIn &lt; 255; fadeIn++) { 
              analogWrite(LED,fadeIn);      
              delay(timeOn); 
          }
      }
  </code></pre>
  
  <p>Here's where I'm stuck. I want to do something similar to the following pseudocode. </p>
  
  <pre><code>activeLED = random(2,10);             // choose a random LED pin
  LEDtoCycle = pinNumber-activeLED;     // set the active LED to the random LED pin 
  cycleLED(pinNumber-activeLED);        // run cycleLED on the active LED
  </code></pre>
  
  <p>My intention is to select an LED at random, then to run <code>cycleLED</code> on that LED, repeating indefinitely. By choosing random However, I'm having a hard time wrapping my head around a good way to do this. How do I pass the pin variable to cycleLED()? Or should I repeatedly <code>#define</code> a single, random LED? Or should I just hardcode eight separate instances of <code>cycleLED1()</code>, <code>cycleLED2()</code>, <code>cycleLED3()</code>, and so forth.  </p>
  
  <p>Tips or suggestions?</p>