core-lightning/common/random_select.c
Rusty Russell 4ffda340d3 check: make sure all files outside contrib/ include "config.h" first.
And turn "" includes into full-path (which makes it easier to put
config.h first, and finds some cases check-includes.sh missed
previously).

config.h sets _GNU_SOURCE which really needs to be done before any
'#includes': we mainly got away with it with glibc, but other platforms
like Alpine may have stricter requirements.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-06 10:05:39 +10:30

13 lines
256 B
C

#include "config.h"
#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;
}