Choosing a random array from a list of arrays

Is there a way to reference a random array from a list of arrays?

Here's what I'd like to be able to do. (I know this doesn't work). I have 42 different arrays and I want to choose one at random.

The array names are array1, array2, array3, etc.

DmxSimple.write(p + 5, array(random(42)) );

Create an array of pointers to your arrays, and then an index into that array "chooses" one.

Or create a two dimensional array, and use your random value as the first index.

AWOL:
Create an array of pointers to your arrays, and then an index into that array "chooses" one.

Can you give me an example, please?

Greetz Chris

Uncompiled, untested

char*strings [] = {"The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog", "."};
const int N_STRINGS = sizeof (strings) /  sizeof (strings[0]);
void setup ()
{
  Serial.begin (115200);
  for (int i = 0; i < 20; i++)
  {
    Serial.println (strings [random (0, N_STRINGS)]);  
  }  
}

void loop ()
{}

Thanks! :slight_smile:

Greetz Chris

PeterH:
Or create a two dimensional array, and use your random value as the first index.

In this case would it be a problem, if the lines have different amount of indexes?

Greetz Chris

Edit: Sorry for posting two times..

In this case would it be a problem, if the lines have different length?

The example in reply #4 doesn't care about size, because the elements are string pointers, but if you need to know the the size of the array you've chosen, and null-termination isn't feasible then you'll need another array (or a struct) to record the size of the array as well.