1 /* 2 * Paretoormal distribution table generator 3 * 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 8 * function. 9 * 10 * Taken from the uncopyrighted NISTnet code. 11 */ 12 #include <stdio.h> 13 #include <stdlib.h> 14 #include <string.h> 15 #include <math.h> 16 #include <limits.h> 17 #include <malloc.h> 18 19 #include <linux/types.h> 20 #include <linux/pkt_sched.h> 21 22 #define TABLESIZE 16384 23 #define TABLEFACTOR NETEM_DIST_SCALE 24 25 static double 26 normal(double x, double mu, double sigma) 27 { 28 return .5 + .5*erf((x-mu)/(sqrt(2.0)*sigma)); 29 } 30 31 static const double a=3.0; 32 33 static int 34 paretovalue(int i) 35 { 36 double dvalue; 37 38 i = 65536-4*i; 39 dvalue = (double)i/(double)65536; 40 dvalue = 1.0/pow(dvalue, 1.0/a); 41 dvalue -= 1.5; 42 dvalue *= (4.0/3.0)*(double)TABLEFACTOR; 43 if (dvalue > 32767) 44 dvalue = 32767; 45 return (int)rint(dvalue); 46 } 47 48 int 49 main(int argc, char **argv) 50 { 51 int i,n; 52 double x; 53 double table[TABLESIZE+1]; 54 55 for (x = -10.0; x < 10.05; x += .00005) { 56 i = rint(TABLESIZE*normal(x, 0.0, 1.0)); 57 table[i] = x; 58 } 59 printf( 60 "# This is the distribution table for the paretonormal distribution.\n" 61 ); 62 63 for (i = n = 0; i < TABLESIZE; i += 4) { 64 int normvalue, parvalue, value; 65 66 normvalue = (int) rint(table[i]*TABLEFACTOR); 67 parvalue = paretovalue(i); 68 69 value = (normvalue+3*parvalue)/4; 70 if (value < SHRT_MIN) value = SHRT_MIN; 71 if (value > SHRT_MAX) value = SHRT_MAX; 72 73 printf(" %d", value); 74 if (++n == 8) { 75 putchar('\n'); 76 n = 0; 77 } 78 } 79 80 return 0; 81 } 82