2 * @author Adam McLaurin
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GN6U General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "RandomNumber.h"
24 #ifdef SOCKETS_NAMESPACE
25 namespace SOCKETS_NAMESPACE
{
28 const unsigned long int RandomNumber::X_SEED_DEFAULT
= 123456789UL;
29 const unsigned long int RandomNumber::Y_SEED_DEFAULT
= 362436069UL;
30 const unsigned long int RandomNumber::Z_SEED_DEFAULT
= 521288629UL;
31 const unsigned long int RandomNumber::W_SEED_DEFAULT
= 88675123UL;
34 RandomNumber::RandomNumber(bool time_shuffle
)
35 :mXSeed(time_shuffle
? (unsigned long)time(NULL
) ^ X_SEED_DEFAULT
: X_SEED_DEFAULT
)
36 ,mYSeed(time_shuffle
? (unsigned long)time(NULL
) ^ Y_SEED_DEFAULT
: Y_SEED_DEFAULT
)
37 ,mZSeed(time_shuffle
? (unsigned long)time(NULL
) ^ Z_SEED_DEFAULT
: Z_SEED_DEFAULT
)
38 ,mWSeed(time_shuffle
? (unsigned long)time(NULL
) ^ W_SEED_DEFAULT
: W_SEED_DEFAULT
)
43 RandomNumber::RandomNumber(
44 unsigned long int x_seed
,
45 unsigned long int y_seed
,
46 unsigned long int z_seed
,
47 unsigned long int w_seed
)
56 RandomNumber::~RandomNumber()
60 void RandomNumber::reset()
68 RandomNumber::operator unsigned long int() const
73 unsigned long int RandomNumber::next()
75 register unsigned long int t
= (mX
^ (mX
<<11));
83 return(mW
= (mW
^ (mW
>>19)) ^ (t
^ (t
>>8)));
86 unsigned long int RandomNumber::skip(unsigned long int s
)
88 for(register unsigned long int i
= 0 ; i
< s
; ++i
)
96 void RandomNumber::getSeed(
97 unsigned long int& x_seed
,
98 unsigned long int& y_seed
,
99 unsigned long int& z_seed
,
100 unsigned long int& w_seed
)
108 unsigned long int RandomNumber::max_random()
110 return(std::numeric_limits
<unsigned long int>::max());
113 #ifdef SOCKETS_NAMESPACE
114 } // namespace SOCKETS_NAMESPACE {