Logo
Explore Help
Sign In
davide/palladum-lightning
1
0
Fork 0
You've already forked palladum-lightning
Code Issues Pull Requests Actions 5 Packages Projects Releases Wiki Activity
Files
42f9361375781d0bfad62efb6c492d0c4e9a3962
palladum-lightning/common/random_select.c

13 lines
256 B
C
Raw Normal View History

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-04 21:53:56 +10:30
#include "config.h"
common/random_select: central place for reservoir sampling. Turns out we can make quite a simple API out of it. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
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;
}
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.25.3 Page: 1101ms Template: 42ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API