2
Copyright (C) 2003-2008 Fons Adriaensen <fons@kokkinizita.net>
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
const double Rngen::_p31 = 2147483648.0;
26
const double Rngen::_p32 = 4294967296.0;
27
const float Rngen::_p31f = 2147483648.0f;
28
const float Rngen::_p32f = 4294967296.0f;
42
void Rngen::init (uint32_t s)
47
if (s == 0) s = time (0);
49
G.set_poly (Prbsgen::G32);
52
for (i = 0; i < 55; i++)
56
while (j--) G.step ();
66
double Rngen::grand (void)
78
a = irand () / _p31 - 1.0;
79
b = irand () / _p31 - 1.0;
82
while ((r > 1.0) || (r < 1e-20));
84
r = sqrt (-2.0 * log (r) / r);
92
void Rngen::grand (double *x, double *y)
98
a = irand () / _p31 - 1.0;
99
b = irand () / _p31 - 1.0;
102
while ((r > 1.0) || (r < 1e-20));
104
r = sqrt (-log (r) / r);
110
float Rngen::grandf (void)
122
a = irand () / _p31f - 1.0f;
123
b = irand () / _p31f - 1.0f;
126
while ((r > 1.0f) || (r < 1e-20f));
128
r = sqrtf (-2.0f * logf (r) / r);
136
void Rngen::grandf (float *x, float *y)
142
a = irand () / _p31f - 1.0f;
143
b = irand () / _p31f - 1.0f;
146
while ((r > 1.0f) || (r < 1e-20f));
148
r = sqrtf (-logf (r) / r);