All other answers so far mention the need to use srand()
to initialize your random number generator, which is a valid point, but is not the problem you're having.
Your problem is that your program computes the modulo of your random number and 1, which is always going to be equal to 0, because for any integer n,
n % 1 == remainder of the integer division of n by 1
== n - (n / 1)
== 0
So, replace this:
random1 = rand() % 1 + 0;
with this:
random1 = rand() % 2;
and you will have something that sort of does what you want. I'm saying "sort of" because there are other issues to consider, such as random number generator initialization (srand()
), using rand()
rather than more elaborate RNGs, etc.