New pct_chance(), for clarity, and symmetry with chance()
This commit is contained in:
parent
1cf6b5e6bb
commit
54ddcd0f5a
10 changed files with 34 additions and 22 deletions
|
@ -27,7 +27,7 @@
|
|||
* chance.c: Roll dice
|
||||
*
|
||||
* Known contributors to this file:
|
||||
*
|
||||
* Markus Armbruster, 2006-2012
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -45,6 +45,15 @@ chance(double d)
|
|||
return d > (random() % 32768) / 32768.0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return non-zero with probability PCT%.
|
||||
*/
|
||||
int
|
||||
pct_chance(int pct)
|
||||
{
|
||||
return roll(100) <= pct;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a random number in [0..N-1].
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue