mirror of
https://git.disroot.org/80486DX2-66/polonium.git
synced 2024-12-26 23:20:22 +05:30
WIP -> main post-merge editing
This commit is contained in:
parent
9ab507cf86
commit
d69b3e8ea9
@ -9,26 +9,6 @@ static bool is_line_ending(byte c);
|
|||||||
|
|
||||||
/* function implementations */
|
/* function implementations */
|
||||||
static bool get_chance(uint16_t desired_chance) {
|
static bool get_chance(uint16_t desired_chance) {
|
||||||
/* TODO: remove this multi-line comment before merging into main branch
|
|
||||||
// algorithm v1
|
|
||||||
// calculate the cumulative distribution function (CDF)
|
|
||||||
uint8_t cdf[UINT8_MAX_PLUS_1];
|
|
||||||
memset(cdf, 0, sizeof(cdf));
|
|
||||||
for (uint8_t i = 0; i < UINT8_MAX; i++)
|
|
||||||
cdf[i] = cdf[i] + ((i - 1) <= desired_chance);
|
|
||||||
|
|
||||||
// generate a random number in the range of 0 to the total weight
|
|
||||||
uint8_t random_number = mt_next() & UINT8_MAX;
|
|
||||||
|
|
||||||
// use the CDF to determine the outcome
|
|
||||||
for (uint8_t i = 0; i < UINT8_MAX; i++)
|
|
||||||
if (random_number < cdf[i])
|
|
||||||
return true;
|
|
||||||
return (random_number < cdf[UINT8_MAX] ||
|
|
||||||
random_number < cdf[UINT8_MAX_PLUS_1]);
|
|
||||||
*/
|
|
||||||
|
|
||||||
// algorithm v2
|
|
||||||
if (desired_chance == UINT16_MAX)
|
if (desired_chance == UINT16_MAX)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user