Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
randgen.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 void rand_initialize (long int seedval)
00029 {
00030 srand48 (seedval);
00031 }
00032
00033
00034
00035
00036
00037
00038
00039 float rand_uniform (float a, float b)
00040 {
00041 return (a + (float)drand48() * (b-a) );
00042 }
00043
00044
00045
00046
00047
00048
00049
00050 float rand_normal (float mu, float var)
00051 {
00052 float u1, u2;
00053 float r, n;
00054
00055
00056 u1 = 0.0;
00057 while (u1 <= 0.0)
00058 {
00059 u1 = rand_uniform (0.0, 1.0);
00060 }
00061 u2 = rand_uniform (0.0, 1.0);
00062
00063 r = sqrt(-2.0*log(u1));
00064 n = r * cos(2.0*PI*u2);
00065
00066 return (mu + n * sqrt(var));
00067 }
00068
00069
00070
00071
00072
00073
00074
00075 void rand_binormal (float mu, float var, float * n1, float * n2)
00076 {
00077 float u1, u2;
00078 float r, sigma;
00079
00080
00081 u1 = 0.0;
00082 while (u1 <= 0.0)
00083 {
00084 u1 = rand_uniform (0.0, 1.0);
00085 }
00086 u2 = rand_uniform (0.0, 1.0);
00087
00088 r = sqrt(-2.0*log(u1));
00089 sigma = sqrt (var);
00090
00091 *n1 = mu + r * cos(2.0*PI*u2) * sigma;
00092 *n2 = mu + r * sin(2.0*PI*u2) * sigma;
00093 }
00094
00095
00096
00097
00098
00099