2021-12-04 21:53:56 +10:30
|
|
|
#include "config.h"
|
2020-08-11 14:35:56 +09:30
|
|
|
#include <common/pseudorand.h>
|
|
|
|
|
#include <common/random_select.h>
|
|
|
|
|
|
|
|
|
|
bool random_select(double weight, double *tot_weight)
|
|
|
|
|
{
|
|
|
|
|
*tot_weight += weight;
|
|
|
|
|
if (weight == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return pseudorand_double() <= weight / *tot_weight;
|
|
|
|
|
}
|