31 #ifndef __RANDOM_NORM_H_
32 #define __RANDOM_NORM_H_
34 int nRandSamples[] = {
35 9, -95, -118, 27, -148, 0, 114, 39, -104, 208, 196, 22, -5, 0, -113, -126,
36 33, -11, 131, 50, -40, 175, -140, 292, -73, 68, -8, -46, -118, 95, -32, 79,
37 164, 138, 41, 16, -48, -32, -70, 20, -30, -169, 26, 64, -36, -76, -81, 201,
38 -80, -61, 0, -39, -108, 23, -59, -6, 35, 153, -15, -112, -9, 32, 151, -52,
39 -38, 28, 24, -24, -216, -12, -49, -2, -18, 133, 10, 77, -58, -240, -189, -36,
40 98, 98, 50, 131, 2, 0, -57, 108, -185, 30, -12, 43, 48, 89, 22, 21,
41 -63, -14, -6, 23, -58, 1, -86, -136, 174, -27, -97, 38, -178, 51, -80, 141,
42 -43, 49, 172, -112, 79, 64, 101, 23, -62, -242, 4, 152, 13, -201, 158, 60,
43 47, -66, 19, -70, 9, -125, 56, 11, -52, 90, -161, 167, 49, -77, -199, 91,
44 52, 203, -81, 26, -23, 45, 59, -20, 4, 32, -161, -4, -101, 118, 218, 47,
45 19, 114, 17, -146, -87, 26, 93, -102, 101, -18, 79, 59, 27, -28, -62, 175,
46 62, 19, 277, -87, -99, 33, 29, 131, -43, -88, -68, -31, -79, -120, 93, -121,
47 -59, -99, 35, -72, 56, 149, 37, -5, 32, 53, 11, -13, -136, 66, -185, -62,
48 138, 0, -8, 147, 41, -160, 82, -128, 59, 80, 106, 4, -196, 23, 111, -91,
49 -7, 45, 134, 78, 185, 44, -17, -41, 16, 100, 93, -20, -140, 113, 39, 102,
50 4, -72, -91, 183, 113, -191, 73, -26, -67, -91, -79, -217, 59, 12, 69, -117,
53 int lastNrandIndex = 0;
67 if (lastNrandIndex > 255)
69 return (nRandSamples[lastNrandIndex] * scale) / 100;
86 for (
int i = 0; i < 12; i++)
90 return ((nr * scale)/100);
102 int iter = precision * 12;
104 long nr = (-iter * 100)/2;
105 for (
int i = 0; i < iter; i++)
109 s = (10000 * iter)/12;
111 return ((nr * scale)/s);
119 int ArrayMax(
long v[])
121 int len = ArrayLen(v);
123 for(
int i = 0; i < len; i++)
125 if (v[i] > max) max = v[i];
132 void TestRandomNorm ()
136 int progressbar, zone;
139 TextOut(0,LCD_LINE1,
"Normal Samples");
140 for (i = 0; i < SAMPLES; i++)
142 progressbar = (100 * i) / SAMPLES;
143 LineOut(0, LCD_LINE2 + 4, progressbar, LCD_LINE2 + 4);
144 LineOut(0, LCD_LINE2 + 3, progressbar, LCD_LINE2 + 3);
148 for (zone = 0; zone < HIST; zone++)
151 if (-300 + zone * 600 / HIST <= r & r < -300 + (zone + 1) * 600 / HIST)
157 max = ArrayMax(stat);
159 for (zone = 0; zone < HIST; zone++)
161 x = (100 * zone)/HIST;
162 h = (63 * stat[zone])/max;
long RandomNorm3(int scale, int precision)
Returns a random number sample from Guassian distribution scaled by the given factor (using sum of un...
long RandomNorm2(int scale)
Returns a random number sample from Guassian distribution scaled by the given factor (using sum of un...
int RandomNorm(int scale)
Returns a random number sample from Guassian distribution scaled by the given factor (using lookup ta...