randgauss.h

Go to the documentation of this file.
00001 
00032 const F32 table[][2] = {
00033 {.00f, .5f},
00034 {.01f, .504f},
00035 {.02f, .508f},
00036 {.03f, .512f},
00037 {.06f, .5239f},
00038 {.08f, .5319f},
00039 {.11f, .5438f},
00040 {.13f, .5517f},
00041 {.16f, .5636f},
00042 {.18f, .5714f},
00043 {.21f, .5832f},
00044 {.23f, .5910f},
00045 {.26f, .6026f},
00046 {.28f, .6103f},
00047 {.31f, .6217f},
00048 {.34f, .6331f},
00049 {.36f, .6406f},
00050 {.39f, .6517f},
00051 {.42f, .6628f},
00052 {.44f, .6700f},
00053 {.47f, .6808f},
00054 {.50f, .6915f},
00055 {.53f, .7019f},
00056 {.56f, .7123f},
00057 {.59f, .7224f},
00058 {.62f, .7324f},
00059 {.65f, .7422f},
00060 {.68f, .7517f},
00061 {.71f, .7611f},
00062 {.74f, .7703f},
00063 {.78f, .7823f},
00064 {.81f, .7910f},
00065 {.85f, .8023f},
00066 {.88f, .8106f},
00067 {.92f, .8212f},
00068 {.96f, .8315f},
00069 {1.0f, .8413f},
00070 {1.04f, .8508f},
00071 {1.09f, .8621f},
00072 {1.13f, .8708f},
00073 {1.18f, .8810f},
00074 {1.23f, .8907f},
00075 {1.29f, .9015f},
00076 {1.35f, .9115f},
00077 {1.41f, .9207f},
00078 {1.48f, .9306f},
00079 {1.56f, .9406f},
00080 {1.65f, .9505f},
00081 {1.76f, .9608f},
00082 {1.89f, .9706f},
00083 {2.06f, .9803f},
00084 {2.33f, .9901f},
00085 {99.0f, 1.0f}};
00086 
00087 inline F32 randGauss(F32 mean, F32 stdev)
00088 {
00089         S32 i = 0;
00090         F32 u = rand() / (F32) RAND_MAX;
00091         F32 n;
00092         
00093         if (u >= 0.5)
00094         {
00095                 while (u > table[i][1])
00096                         i++;
00097                 
00098                 n = table[i-1][0];
00099                 
00100         } else {
00101                 u = 1 - u;
00102                 while (u > table[i][1])
00103                         i++;
00104                 n = 1 - table[i-1][0];
00105         }
00106         //printf("u: %f, n: %f, i: %d\n", u, n, i);     //debug
00107         
00108         return (mean + stdev * n);
00109 }
00110 

Generated on Thu Jul 1 06:09:59 2010 for Second Life Viewer by  doxygen 1.4.7