]>
git.proxmox.com Git - mirror_iproute2.git/blob - netem/paretonormal.c
2 * Paretoormal distribution table generator
4 * This distribution is simply .25*normal + .75*pareto; a combination
5 * which seems to match experimentally observed distributions reasonably
6 * well, but is computationally easy to handle.
7 * The entries represent a scaled inverse of the cumulative distribution
10 * Taken from the uncopyrighted NISTnet code.
19 #include <linux/types.h>
20 #include <linux/pkt_sched.h>
22 #define TABLESIZE 16384
23 #define TABLEFACTOR NETEM_DIST_SCALE
26 normal(double x
, double mu
, double sigma
)
28 return .5 + .5*erf((x
-mu
)/(sqrt(2.0)*sigma
));
31 static const double a
=3.0;
39 dvalue
= (double)i
/(double)65536;
40 dvalue
= 1.0/pow(dvalue
, 1.0/a
);
42 dvalue
*= (4.0/3.0)*(double)TABLEFACTOR
;
45 return (int)rint(dvalue
);
49 main(int argc
, char **argv
)
53 double table
[TABLESIZE
+1];
55 for (x
= -10.0; x
< 10.05; x
+= .00005) {
56 i
= rint(TABLESIZE
*normal(x
, 0.0, 1.0));
60 "# This is the distribution table for the paretonormal distribution.\n"
63 for (i
= n
= 0; i
< TABLESIZE
; i
+= 4) {
64 int normvalue
, parvalue
, value
;
66 normvalue
= (int) rint(table
[i
]*TABLEFACTOR
);
67 parvalue
= paretovalue(i
);
69 value
= (normvalue
+3*parvalue
)/4;
70 if (value
< SHRT_MIN
) value
= SHRT_MIN
;
71 if (value
> SHRT_MAX
) value
= SHRT_MAX
;