I'm writing in C. I am trying to get a simple way to generate a random number between 0 and 1. I'm not sure of two things - how to limit a random number to 0 or 1 and how to reset it every time I hit the "Enter" key.
I want to try to do something simple like a coin flip.
Each time the person presses enter, a random number is generated and if it is 0 it's heads and if 1 it's tails. I'm fairly new at C and am not sure exactly what to do.
To start, here's what I've done so far (trying to just get a random number). I do not know how to limit it to 0 and 1. This gives me the same number every time I run it. Thanks!
#include <stdio.h>
int main()
{
int x = rand();
printf("%d",x);
return 0;
}