osdl.net!shemminger | dfe6094 | 2005-02-09 22:05:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Normal distribution table generator |
| 3 | * Taken from the uncopyrighted NISTnet code. |
| 4 | */ |
| 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <math.h> |
| 8 | #include <string.h> |
| 9 | #include <limits.h> |
| 10 | |
| 11 | #include <linux/types.h> |
| 12 | #include <linux/pkt_sched.h> |
| 13 | |
| 14 | #define TABLESIZE 16384 |
| 15 | #define TABLEFACTOR NETEM_DIST_SCALE |
| 16 | |
| 17 | static double |
| 18 | normal(double x, double mu, double sigma) |
| 19 | { |
| 20 | return .5 + .5*erf((x-mu)/(sqrt(2.0)*sigma)); |
| 21 | } |
| 22 | |
osdl.net!shemminger | f8f9de5 | 2005-03-30 18:11:49 +0000 | [diff] [blame] | 23 | |
osdl.net!shemminger | dfe6094 | 2005-02-09 22:05:41 +0000 | [diff] [blame] | 24 | int |
| 25 | main(int argc, char **argv) |
| 26 | { |
osdl.net!shemminger | dfe6094 | 2005-02-09 22:05:41 +0000 | [diff] [blame] | 27 | int i, n; |
osdl.net!shemminger | f8f9de5 | 2005-03-30 18:11:49 +0000 | [diff] [blame] | 28 | double x; |
| 29 | double table[TABLESIZE+1]; |
osdl.net!shemminger | dfe6094 | 2005-02-09 22:05:41 +0000 | [diff] [blame] | 30 | |
| 31 | for (x = -10.0; x < 10.05; x += .00005) { |
osdl.net!shemminger | f8f9de5 | 2005-03-30 18:11:49 +0000 | [diff] [blame] | 32 | i = rint(TABLESIZE * normal(x, 0.0, 1.0)); |
osdl.net!shemminger | dfe6094 | 2005-02-09 22:05:41 +0000 | [diff] [blame] | 33 | table[i] = x; |
| 34 | } |
| 35 | |
Stephen Hemminger | e9e9365 | 2016-03-27 10:47:46 -0700 | [diff] [blame] | 36 | |
osdl.net!shemminger | dfe6094 | 2005-02-09 22:05:41 +0000 | [diff] [blame] | 37 | printf("# This is the distribution table for the normal distribution.\n"); |
| 38 | for (i = n = 0; i < TABLESIZE; i += 4) { |
| 39 | int value = (int) rint(table[i]*TABLEFACTOR); |
| 40 | if (value < SHRT_MIN) value = SHRT_MIN; |
| 41 | if (value > SHRT_MAX) value = SHRT_MAX; |
| 42 | |
| 43 | printf(" %d", value); |
| 44 | if (++n == 8) { |
| 45 | putchar('\n'); |
| 46 | n = 0; |
| 47 | } |
| 48 | } |
osdl.net!shemminger | f8f9de5 | 2005-03-30 18:11:49 +0000 | [diff] [blame] | 49 | |
osdl.net!shemminger | dfe6094 | 2005-02-09 22:05:41 +0000 | [diff] [blame] | 50 | return 0; |
| 51 | } |