sort order return

I'm having trouble sorting through language differences in getting back into this. It had been a while and i have syntax from C++, Java, and python making a lot of noise over top of the compiler syntax here.
I'm trying to make an order randomizer, in this case, I'm just trying to see the final array in some way. I think I've botched at least the output, and oh by the way I'm exhausted from getting this far weeding through the cross-language pseudocode in my head.

suggestions greatly appreciated
-cb

  int len = 32;
  int outArray[32];

void setup(){
  Serial.begin(9600);


}
void loop(){
  uint8_t a;
  populator(outArray);
  for( a = 0; a <len; a++)
  {
    Serial.print(outArray[a]);
  }
  Serial.println();
  delay(1000);
}

void populator(int outIndexes[] ) 
{
  //build scrambled index array where each index is used only once
  bool indexCheck[len];
  uint8_t i;
  int ix;
  
  for( i=0; i<len; i++)
  {
    indexCheck[i]=true;
  }
  //fill array with marker data
  for( i=0; i<len; i++)
  {
    outIndexes[i]=len+1;
  }

  //iterate through output array, assigning index by rand%numPixels

  for( i=0; i<len; i++)
  {
    while(outIndexes[i]=len+1)
    {
      ix=random(len);
      if(indexCheck[ix]){
	  outIndexes[i]=ix;
	  indexCheck[ix]=false;}
    }
  }
}

Debugging with serial print shows I have an infinite loop while trying to verify and populate the index list.
Am I using random inproperly?

while(outIndexes*=len+1)*

  • {*
  • Serial.println('e');*
  • ix=random(len);*
  • if(indexCheck[ix]){*
    _ outIndexes*=ix;_
    _
    indexCheck[ix]=false;}_
    _
    }[/quote]*_
while(outIndexes[i]=len+1)

Nail-head contact point - 33 is ALWAYS true.
Did you mean == ?

yep :expressionless:
ouch, comparison/assignment err

works much better now!
Thanks so much

Thanks AWOL, last night I sat bolt upright in bed realizing a better way to do the sorting, and how slow this one was.
But, I also was trying to figure out a timing issue, and I thought about using the two flaws together interestingly.
Using a LPD8806, I had the sorting array update the strip as it found a new index location. As the newness of the array fills up, it takes a good while longer to generate enough numbers to hit a new one - a tried and true lame programming move.

But a good delay pattern for cycling through updating the colors to let them hang on for a little while without an actual delay() call. (just plenty of wasted calls to random())

#include <avr/pgmspace.h>
#include "SPI.h"
#include "LPD8806.h"



const int len = 32;       //number of pixels
int outArray[len];    //also used here
int dataPin = 16;
int clockPin = 15;


LPD8806 strip = LPD8806(len, dataPin, clockPin);
void populator(int outIndexes[] ); 

void setup(){
  Serial.begin(9600);
  strip.begin();
  randomSeed(analogRead(0));
  strip.show();


}
void loop(){
  //uint8_t a, r, g, b;
  
  Serial.println('a');
  populator(outArray);
 
    
  /*for( a = 0; a <len; a++)//debug printing the array
  {
    Serial.print(outArray[a]);
    Serial.print(',');
  }
  Serial.println();*/
  
  delay(1000);
}

void populator(int outIndexes[] ) 
{
  //build scrambled index array where each index is used only once
  bool indexCheck[len];
  uint8_t i, r, g, b;
  int ix;
  Serial.println('b');
  for( i=0; i<len; i++)
  {
    indexCheck[i]=true;
  }
  //clear array with invalid data
  for( i=0; i<len; i++)
  {
    outIndexes[i]=len+1;
  }

  //iterate through output array, assigning index by rand%numPixels
  Serial.println('c');
  for( i=0; i<len; i++)
  {
    Serial.println('d');
    while(outIndexes[i]==len+1)
    { 
      Serial.println('e');
      ix=random(len);
      if(indexCheck[ix])
      {
        outIndexes[i]=ix;
	indexCheck[ix]=false;
        r=random(127);
        g=random(127);
        b=random(127);
        strip.setPixelColor(ix, r, g, b);
        strip.show();

      }
    }
  }
}

Shuffle:

// -- see: http://en.wikipedia.org/wiki/Fisher-Yates_shuffle

void shuffle (int * t, int n)
  {
  while (--n >= 2)
    {
    // n is now the last pertinent index
    int k = random (n); // 0 <= k <= n - 1
    // Swap
    int temp = t [n];
    t [n] = t [k];
    t [k] = temp;
    } // end of while
 
  }  // end of shuffle

const int NUM = 30;  // how many

void setup ()
{
  int t [NUM];
  
  // populate table
  for (int i = 0; i < NUM; i++)
    t [i] = i;
    
  // shuffle it
  shuffle (t, NUM);
  
  // print table
  Serial.begin (115200);
  for (int i = 0; i < NUM; i++)
    Serial.println (t [i]);
}  // end of setup

void loop () {}

Output:

26
13
3
11
7
18
14
27
15
6
19
20
1
4
25
12
2
22
17
29
9
24
0
28
8
5
10
23
21
16