Using the following function, write a function that returns a 0 or a 1 with equal probability.
int random() {
return ((rand() % 5) + 1);
}
Like most of the interview questions that I ask, I’m not looking for a specific answer, I just want to see their thought process in identifying problems and coming up with solutions to those problems. But a candidate today quickly got lost in the weeds on this and I want to make sure I’m being fair. Maybe the main problem was that the candidate didn’t know what the % operator did.