summaryrefslogtreecommitdiff
path: root/ce/test/common/src/gaussian.c
blob: 4d2ca63e93bef0e74ca16d7d5e8d79b1a7a6cccc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    ce/test/common/src/gaussian.c
 * \brief   generate double float number with a normal repartition (gaussian).
 * \ingroup ce/test/common
 *
 */
#include "common/std.h"
#include <math.h>
#include "ce/test/common/gaussian.h"

double
lib_rnd_gaussian (lib_rnd_t *ctx, double lambda, double sigma)
{
    double a_rnd = 0;
    while (a_rnd == 0) a_rnd=lib_rnd_uniform (ctx,100000);
    a_rnd = a_rnd / 100000.0;
    double b_rnd = lib_rnd_uniform (ctx,100000)/100000.0;
    double lna = log (a_rnd);
    double gauss_rnd = sqrt (-2*lna)* cos (2*3.14*b_rnd);
    return (lambda + sigma *gauss_rnd);
}