rand() returns a number between 0 and RAND_MAX, so you would want something like
a = 1 + (int)(3.0*rand()/(RAND_MAX+1.0));
for an integer between 1 and 3 inclusive. If you want between 0 and 3, use
a = (int)(4.0*rand()/(RAND_MAX+1.0));
because 4.0*rand() is at most 4*RAND_MAX, so when you divide by RAND_MAX+1.0, you get a number which is slightly less than 4 at most, and thus rounded down to 3.
Don't use code like
a = 1 + (int)(rand() % 3);
because it emphasises a subset of bits of the random number, and thus is inherently less random. (Think of the rules you learned in primary school to determine whether a number is divisible by 2, 3, 4, ... .)