1 // Copyright (C) 2006-2008 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <sys/types.h>
24 // #include "mt19937ar.h
25 extern void init_by_array(unsigned long [], int);
26 extern double genrand_real1(void);
27 extern double genrand_real3(void);
33 static void initrand(void)
37 31081996, 21012006, 17921963, 0,
38 11101998, 2112003, 25111964, 0
43 vec[3] = vec[7] = 2082007;
45 vec[3] = (unsigned long) getpid();
46 vec[7] = (unsigned long) time(NULL);
48 init_by_array(vec, 8);
53 /*static void initrand(void)
57 31081996, 21012006, 17921963, 0,
58 11101998, 2112003, 25111964, 0
62 vec[3] = (unsigned long) getpid();
63 vec[7] = (unsigned long) time(NULL);
64 init_by_array(vec, 8);
69 static double randGauss(void)
81 next = 2.0*genrand_real3() - 1.0;
82 v2 = 2.0*genrand_real3() - 1.0;
83 d = next*next + v2*v2;
84 } while (d >= 1.0 || d == 0.0);
85 fac = sqrt(-2.0*log(d)/d);
94 Aleatoire::Aleatoire(long sz)
100 void Aleatoire::fill(std::vector<double> &ret)
104 for (i=0; i<size; i++) ret[i] = tire();
107 std::vector<double> *Aleatoire::gen()
109 std::vector<double> *ret;
111 ret = new std::vector<double>(size);
119 return genrand_real1();
122 // class NormalPositif
123 double NormalePositif::tire()
125 return randGauss() * 0.25 + 0.5 ;
129 double Normale::tire()
135 void Sphere::fill(std::vector<double> &ret)
141 for (cum=0, i=0; i<size; i++)
142 cum += ret[i] * ret[i];
144 r = pow(genrand_real1(), size);
145 for (i=0; i<size; i++)
149 // class SpherePositif
150 void SpherePositif::fill(std::vector<double> &ret)
155 for (i=0; i<size; i++)
156 ret[i] = fabs(ret[i]);