blob: e6683db8946680910815b05ac8be96b80449e819 [file] [log] [blame]
osdl.net!shemmingerdfe60942005-02-09 22:05:41 +00001/*
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
17static double
18normal(double x, double mu, double sigma)
19{
20 return .5 + .5*erf((x-mu)/(sqrt(2.0)*sigma));
21}
22
23int
24main(int argc, char **argv)
25{
26 double x, *table;
27 int i, n;
28
29 table = calloc(sizeof(double), TABLESIZE+1);
30 if (!table) {
31 fprintf(stderr, "Not enough memory\n");
32 return 1;
33 }
34
35
36 for (x = -10.0; x < 10.05; x += .00005) {
37 i = (int)rint(TABLESIZE*normal(x, 0.0, 1.0));
38 table[i] = x;
39 }
40
41
42 printf("# This is the distribution table for the normal distribution.\n");
43 for (i = n = 0; i < TABLESIZE; i += 4) {
44 int value = (int) rint(table[i]*TABLEFACTOR);
45 if (value < SHRT_MIN) value = SHRT_MIN;
46 if (value > SHRT_MAX) value = SHRT_MAX;
47
48 printf(" %d", value);
49 if (++n == 8) {
50 putchar('\n');
51 n = 0;
52 }
53 }
54 free(table);
55 return 0;
56}