squiggle.c

Self-contained Monte Carlo estimation in C99
Log | Files | Refs | README

commit 4dad518d3f39bb3787d6486d0999b7a79feccd34
parent 3f709159036363345896546e3b4c11591daa6019
Author: NunoSempere <nuno.sempere@protonmail.com>
Date:   Sat, 22 Jul 2023 22:24:22 +0200

add efficient beta distribution

Diffstat:
Msquiggle.c | 7+++++++
1 file changed, 7 insertions(+), 0 deletions(-)

diff --git a/squiggle.c b/squiggle.c @@ -4,6 +4,7 @@ #include <stdint.h> #include <stdio.h> #include <stdlib.h> +#include <sys/types.h> #include <time.h> #define MAX_ERROR_LENGTH 500 @@ -109,6 +110,12 @@ float sample_gamma(float alpha, uint32_t* seed){ } } +float sample_beta(float a, float b, uint32_t* seed){ + float gamma_a = sample_gamma(a, seed); + float gamma_b = sample_gamma(b, seed); + return a / (a + b); +} + // Array helpers float array_sum(float* array, int length) {