title: Randomizing Switch
body: <p>How can I create a random loop for this code so that it does not do the same case all the time and also this is a function being called in to the main. Hope this helps a bit more i was just thinking of using the rand() function.</p>
  
  <pre><code>int escapeRoom()
  { 
      alt_u16 wheels;
      alt_u16 Bumper;
      int i;
  
          Bumper = IORD_ALTERA_AVALON_PIO_DATA(EXPANSION_JP1_BASE);
          Bumper = rand() &amp; (LEFT_FRONT_BUMPER | RIGHT_FRONT_BUMPER);   
  
         switch(Bumper)
          {
              case BOTH_BUMPERS:
              wheels = BACKWARDS;
              IOWR_ALTERA_AVALON_PIO_DATA(EXPANSION_JP1_BASE, wheels);
              break;
  
              case RIGHT_FRONT_BUMPER:
              wheels = RIGHT_BACKWARDS;
              IOWR_ALTERA_AVALON_PIO_DATA(EXPANSION_JP1_BASE, wheels);
              break;
  
              case LEFT_FRONT_BUMPER:
              wheels = LEFT_BACKWARDS;
              IOWR_ALTERA_AVALON_PIO_DATA(EXPANSION_JP1_BASE, wheels);
              break;
  
              case NO_BUMPERS:
              wheels = FORWARD;
              IOWR_ALTERA_AVALON_PIO_DATA(EXPANSION_JP1_BASE, wheels);
              break;
  
              for (i=1 ; i&lt;5 ; i++) ;
              {
              IOWR_ALTERA_AVALON_PIO_DATA(EXPANSION_JP1_BASE, !wheels);
              }  
              break;
  
          }
  }
  </code></pre>