[solved]Shuffle array of integers to randomize setCursor() & lcd.print()

I've written a little program that stores input from the serial console into an array
named LCDarray[rows][cols] and prints with the LiquidCrystal.h library.

I want the function below to initialize a new array of int[MAX], shuffle that array,
and then select the cursor position and array position of LCDarray[][]
with the values inside the int[] array elements.

I understand I haven't seeded it, I'm working on getting it working for now :disappointed_relieved:
For my 'y' value I just alternate between 0 and 1. (random enough for now)

The function prints a (seemingly) random amount of the array LCDarray[][] and I'm wracking my brain trying to figure it out.

int randomWriteArray2(char LCDarray[][cols]){
  int k=0, r=0, temp=0, orderCols[MAX];

  //initialize array as "0"..."'cols-1'0"..."'cols-1'"
  for(k=0;k<MAX;k++)orderCols[k]=(k%cols);
  
  //randomize loop
  for (k=0;k<MAX;k++){
    //pick random number from 0-MAX
    r=random(MAX);
    //hold element k as temp
    temp=orderCols[k];
    //swap in randomly selected element
    orderCols[k]=orderCols[r];
    //replace randomly selected element with temp
    orderCols[r] = temp;
  }
  //LCD write loop
  for(k=0;k<MAX;k++){
    lcd.setCursor(orderCols[k],k%cols);//move cursor to xy
    lcd.write(LCDarray[k%cols][orderCols[k]]);//write LCDarray[y,x]
    delay(100);//for the random look effect
  }
  return 0;//this is the numChar counter, set to 0 so write functions will not write
}

In the hopes anyone could help I commented the crap out of it.
The LCDarray is properly loaded (I checked) and the orderCols[] array is properly shuffled (enough for me anyways) with no repeated numbers or lost numbers(0 to 15 x2), the damn thing just won't write to the LCD properly.

I looked at your code, didn't see anything immediately wrong, but not knowing what "col" is for example doesn't help.

If this is any use, this is a shuffle example I wrote a while back:

// -- 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 () {}

No, like I said it shuffles fine.
col is columns, number of columns. I'm working on a 16x2 HD44780 type lcd on a Teensy++.
MAX is rows*cols.
So for my purposes cols=16, MAX=32

Oh, OK.

... the damn thing just won't write to the LCD properly.

Can you give a more technical description? Writes blanks? Garbage? Partly writes?

Don't cross-post please. It just wastes time and resources while some people respond to one thread and others to another. Your other post deleted.

I placed markers into the program as Console.print() statements to track the integers it was sending to

    lcd.setCursor(orderCols[k],k%cols);//move cursor to xy
    lcd.write(LCDarray[k%cols][orderCols[k]]);//write LCDarray[y,x]

These are the values it gave me... I don't see any problem with the values.
It alternates between 0 and 1, oh... damnit I know what the problem is. I'm not tracking whether I printed (0,7) or something twice...

So I print the same spots more than once a random number of times... :roll_eyes:

0,7

1,1

0,9

1,5

0,9

1,0

0,8

1,13

0,12

1,13

0,6

1,10

0,12

1,6

0,3

1,14

0,7

1,11

0,15

1,4

0,14

1,2

0,11

1,8

0,2

1,0

0,5

1,4

0,10

1,15

0,1

1,3

So that's the problem solved, now to find a way to implement that and still get my random numbers.
I guess I can generate a multidimensional array of 1-16.