Improved the CHANCE implementation a bit.

This makes the implementation more uniform (avoiding skew caused
by %).
This commit is contained in:
diligentcircle 2021-08-20 17:48:18 -04:00
parent bc4a022db8
commit 344c5d3c82
1 changed files with 3 additions and 2 deletions

View File

@ -29,8 +29,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define WRAP_ADD(x, y, a, b) x = (((x) + (y)) + \
((x) + (y) < (a) ? ((b) - (a)) : 0) + \
((x) + (y) > (b) ? ((a) - (b)) : 0))
#define CHANCE(x) ((rand() % RAND_MAX) < ((x) * RAND_MAX))
#define RANDRANGE(x, y) (((x) < (y)) ? ((x) + (rand() % (long)(1 + (y) - (x)))) : (x))
#define CHANCE(x) (((double)rand() / ((double)RAND_MAX+1)) < (x))
#define RANDRANGE(x, y) (((x) < (y)) ? \
((x) + (rand() % (long)(1 + (y) - (x)))) : (x))
#define DRAND ((double)rand() / RAND_MAX)
#define _(s) gettext(s)
#define CSDLP(x) (((x) == SDL_PRESSED) ? 1 : 0)