Linking an array, to an array... with variables

the following code works beautifully! whilst wishing to generate a list of numbers between 1 and 6 (0 and 5 for the array), and to not have adjacent repeating numbers

int randNumber;
int randNumberOld;
int fr, ba, le, ri, to, bo;
int sides[6]={fr, ba, le, ri, to, bo};
int puzzleSteps = 10;
int puzzle1[10];

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

  randomSeed(analogRead(0));
  randNumber = random(6);
}

void loop() {
  randNumber = random(6);

  for (int i; i < puzzleSteps; i++) {
    puzzle1[i] = randNumber;
    randNumberOld = randNumber;
      randNumber = random(6);
      while (randNumber==randNumberOld) randNumber=random(6);
      randNumberOld=randNumber;      
  }


  
  for (int i; i < puzzleSteps; i++) {
  Serial.print(puzzle1[i]); Serial.print(" "); 
  }
  
  Serial.println(); 

  delay(50);
}

the following code outputs

1 3 4 3 5 0 5 3 4 5 
4 1 0 2 0 5 2 1 5 4 
2 5 2 4 3 4 0 4 5 1 
0 4 2 0 3 5 4 2 3 2 
2 3 5 0 3 2 1 5 3 4 
2 3 1 3 2 5 2 4 0 3 
2 1 5 1 5 1 5 0 4 5 
0 1 5 2 5 2 1 3 0 2 
2 0 4 1 3 2 3 4 0 3 
2 5 3 0 4 3 0 3 0 4 
4 0 1 0 1 0 1 3 2 5 
2 5 0 1 3 1 4 3 0 3 
1 4 0 5 0 3 1 5 2 1 
5 4 2 4 5 2 5 0 1 0

now i have my puzzle1 generation tool, i now need to map that to the sides, so that;

int sides[6]={fr, ba, le, ri, to, bo};
is equivalent to
int sides[6]={0,1,2,3,4,5,6};

the variables fr, ba, le, ri, to and bo all hold a number (not described here) from 0-255 and i need to keep that number, so i cant just assign a fr=0, le=1 etc.

  for (int i; i < puzzleSteps; i++) {
  puzzle1[i] = sides[i];
  Serial.print(sides[i]); Serial.print(" "); 
  }

returns 0's.

the output i would like;

would be something along the lines of

fr ba bo to fr le ri le fr bo
ba to fr ba le to le ba bo

etc

int sides[6]={0,1,2,3,4,5,6};

7lbs of stuff in a 6lb bag?

Have you thought about using multidimensional arrays to store you multidimensional arrays?

hi you need to change

int sides[6]={fr, ba, le, ri, to, bo};

to

String sides[6]={"fr", "ba", "le", "ri ", "to", "bo"};

and

and Serial.print(sides[i]); Serial.print(" ");

to

Serial.print(sides[puzzle1[i]); Serial.print(" ");

like this:

for (int i; i < puzzleSteps; i++) {
    Serial.print(sides[puzzle1[i]]); Serial.print(" ");
  }

Might be a good idea to initialize 'i' to a known value!

for ( int i; i < puzzleSteps; i++ )

lloyddean:
Might be a good idea to initialize 'i' to a known value!

for ( int i; i < puzzleSteps; i++ )

good idea! i think it always ints to 0, but its better to be safe!

BulldogLowell:

int sides[6]={0,1,2,3,4,5,6};

7lbs of stuff in a 6lb bag?

Have you thought about using multidimensional arrays to store you multidimensional arrays?

ack.. 0 to 5... -:: LOL ::-!

i didnt even know multidimensional arrays existed! thanks

kelvinmead:
good idea! i think it always ints to 0, but its better to be safe!

Stack based variables are never auto initialized, well except for those backed by a struct/class based constructor!

spirit:
hi you need to change

hey, thanks for this... after i fixed a minor issue of trying to push a number onto a string variable, this is working beautifully!

kelvinmead:
good idea! i think it always ints to 0, but its better to be safe!

It doesn't. Static variables and ones defined outside the main loop are initialised. Variables that are located on the stack - 'automatic' variables - will contain whatever happens to be in memory at that location.

spirit:
hi you need to change

int sides[6]={fr, ba, le, ri, to, bo};

to

String sides[6]={"fr", "ba", "le", "ri ", "to", "bo"};

and

No, no, no. Please just no.

kelvinmead:
ack.. 0 to 5... -:: LOL ::-!

i didnt even know multidimensional arrays existed! thanks

Kind of sad that the reference page doesn't even mention them.

aarg:
No, no, no. Please just no.

ok, so what would be yes, yes, yes, god, yes...

the current code is working. i realise that this has converted the variable into a text string.