I want to generate a random boolean for use in a game, so it does not need to be cryptographically secure. I will use stdbool.h
in my code, and I have also done #include <stdlib.h>
. Preferably, it should be very fast (as I will be generating many of them), and it should be able to be done in C89 (just preference). I am not interested at all in doing this in C++.
Here are some of the ways I've come up with:
- read from /dev/urandom, filter out single digits and >5 = true, <5 = false.
- keep calling rand() and filter out low/high values.