(int)Random.range never return upper bound. Random.Range(0,1) will return always 0, Random.Range(0,2) will return 0 or 1.
If you have 20 cases your code might get too much sphagetti. You might use a scope in which your bools in mecanim will have standarized names like Attack1, Attack2,
Than you just use :
int number = Random.Range(1,20);
anim.SetBool ("Attack"+number, true);
Random.Range provides two versions: one which handles int values, and another which handles float values.
When it comes to floats, you give a min and max, and get a random number back. Simple!
When it comes to ints, you give a min and max, and get a number between min and max-1 back. Why the “off by one”? It’s intended to make it easier to use for certain cases, but in your case it looks like it’s doing the opposite.
So, Random.Range(0,1) is effectively asking for a random number: either zero or zero. Oops. Luckily, now that you know that, it’s an easy fix:
switch (Random.Range(0,2)) //returns either 0 or 1
When it comes specifically to a “coin toss”, I sometimes do something like this:
float chance = 0.5f; //chance of heads
bool heads = Random.value < chance; //did we flip heads?
You don’t usually need that temp variable “a” to hold the value, unless you’re going to use it again or it makes things more readable for you.