Krita Source Code Documentation
Loading...
Searching...
No Matches
gauss Class Reference

#include <gauss.h>

Static Public Member Functions

static double gaussian (double, double, int)
 

Detailed Description

Definition at line 10 of file gauss.h.

Member Function Documentation

◆ gaussian()

double gauss::gaussian ( double mean,
double std,
int seed )
static

This function takes as parameters real valued mean and standard-deviation, and an integer valued seed. It returns a real number which may be interpreted as a sample of a normally distributed (Gaussian) random variable with the specified mean and standard deviation. After the first call to gauss, the seed parameter is ignored.

The computational technique used is to pass a uniformly distributed random number through the inverse of the Normal Distribution function.

SPDX-FileCopyrightText: 1982-1989 Donald H. House x@unk.nosp@m.nown.nosp@m..com SPDX-FileCopyrightText: 1989 Robert Allen x@unk.nosp@m.nown.nosp@m..com SPDX-License-Identifier: GPL-2.0-or-later

Definition at line 20 of file gauss.cpp.

21{
22
23#define itblmax 20 /* length - 1 of table describing F inverse */
24#define didu 40.0 /* delta table position / delta ind. variable */
25 /* itblmax / 0.5 */
26
27 /* interpolation table for F inverse */
28 static double tbl[] = {0.00000E+00, 6.27500E-02, 1.25641E-01, 1.89000E-01,
29 2.53333E-01, 3.18684E-01, 3.85405E-01, 4.53889E-01,
30 5.24412E-01, 5.97647E-01, 6.74375E-01, 7.55333E-01,
31 8.41482E-01, 9.34615E-01, 1.03652E+00, 1.15048E+00,
32 1.28167E+00, 1.43933E+00, 1.64500E+00, 1.96000E+00,
33 3.87000E+00
34 };
35
36 static int first_time = 1;
37
38 double u;
39 double di;
40 int index, minus;
41 double delta, gaussian_random_value;
42
43 if (first_time) {
44 srand48(seed);
45 first_time = 0;
46 }
47 /*
48 compute uniform random number between 0.0 - 0.5, and a sign with
49 probability 1/2 of being either + or -
50 */
51 u = drand48();
52 if (u >= 0.5) {
53 minus = 0;
54 u = u - 0.5;
55 }
56 else {
57 minus = 1;
58 }
59 /* interpolate gaussian random number using table */
60
61 index = (int)(di = (didu * u));
62 if (index == itblmax) {
63 delta = tbl[index];
64 }
65 else {
66 di -= index;
67 delta = tbl[index] + (tbl[index + 1] - tbl[index]) * di;
68 }
69 gaussian_random_value = mean + std * (minus ? -delta : delta);
70
71 return(gaussian_random_value);
72}
qreal u
#define itblmax
#define didu

References didu, itblmax, and u.


The documentation for this class was generated from the following files: