int rand=random(0,2);
This will result in rand containing either 0 or 1. The upper limit is the smallest number not returned. Why? A dumb decision by the Arduino team.
i hope that you can give me a better solution
When you find your self doing the same thing over and over, it's time to write a function. That and arrays would eliminate more than 90% of your code.