user21282: I have a recurring problem that when I'm controlling leds, I make several different functions for different fx and just want to trigger them randomly but having a hard time to formulate it in an intelligent way and end up hardcoding every function call.
ex: I have let's say 10 functions called anim1();, anim2();, anim3(); etc 
and would like to called them randomly in that fashion :
randNumber = random(1,11);
anim[randNumber]();

I know that it's not that type of brackets I need to use but I can't find the proper syntax and I'm wondering if it's possible to do that..
I'm sure there must be a way ;)
thanks for your help

user4143: What you want is an array of function pointers.
void anim1() {
    // blah blah
}

void anim2() { 
    // blah blah
}
// ... etc ...

typedef void (*animptr)();

animptr anims[10] = {
    anim1,
    anim2,
    anim3,
    // ... etc ...
    anim10
};

Then you can use:
anims[animNumber]();


21282: <p>I have a recurring problem that when I'm controlling leds, I make several different functions for different fx and just want to trigger them randomly but having a hard time to formulate it in an intelligent way and end up hardcoding every function call.</p>

<p>ex: I have let's say 10 functions called anim1();, anim2();, anim3(); etc 
and would like to called them randomly in that fashion :</p>

<pre><code>randNumber = random(1,11);
anim[randNumber]();
</code></pre>

<p>I know that it's not that type of brackets I need to use but I can't find the proper syntax and I'm wondering if it's possible to do that..
I'm sure there must be a way ;)</p>

<p>thanks for your help</p>
 4143: <p>What you want is an <em>array of function pointers</em>.</p>

<pre><code>void anim1() {
    // blah blah
}

void anim2() { 
    // blah blah
}
// ... etc ...

typedef void (*animptr)();

animptr anims[10] = {
    anim1,
    anim2,
    anim3,
    // ... etc ...
    anim10
};
</code></pre>

<p>Then you can use:</p>

<pre><code>anims[animNumber]();
</code></pre>
