Trying to create the following function in C:
bool randBool(double bias)
which returns either 0 or 1 randomly.
The part that is tripping me up is that I would like to allow for the user to input a "bias" in the range [-1.0, 1.0], which represents the likelihood that the output will be 0 or 1.
Here are a few examples of how the inputted bias should influence the function:
=======================================================
randBool(-1.0) should return 0 100% of the time.
randBool(1.0) should return 1 100% of the time.
randBool(-0.5) is 50% more likely to return 0 than 1.
randBool(0.05) is 5% more likely to return 1 than 0.
randBool(0.0) is no more likely to return 0 than 1.
=======================================================
I am almost certain that this is a probability problem, but I am not so familiar with the topic, so I am stumped on how to implement this function.