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