Merge pull request #622 from worktycho/registerfix
Removed register keyword from Messinne Twister
This commit is contained in:
commit
67d7d83726
@ -162,9 +162,9 @@ inline void MTRand::initialize( const uint32 seed )
|
|||||||
// See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier.
|
// See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier.
|
||||||
// In previous versions, most significant bits (MSBs) of the seed affect
|
// In previous versions, most significant bits (MSBs) of the seed affect
|
||||||
// only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto.
|
// only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto.
|
||||||
register uint32 *s = state;
|
uint32 *s = state;
|
||||||
register uint32 *r = state;
|
uint32 *r = state;
|
||||||
register int i = 1;
|
int i = 1;
|
||||||
*s++ = seed & 0xffffffffUL;
|
*s++ = seed & 0xffffffffUL;
|
||||||
for( ; i < N; ++i )
|
for( ; i < N; ++i )
|
||||||
{
|
{
|
||||||
@ -178,8 +178,8 @@ inline void MTRand::reload()
|
|||||||
// Generate N new values in state
|
// Generate N new values in state
|
||||||
// Made clearer and faster by Matthew Bellew (matthew.bellew@home.com)
|
// Made clearer and faster by Matthew Bellew (matthew.bellew@home.com)
|
||||||
static const int MmN = int(M) - int(N); // in case enums are unsigned
|
static const int MmN = int(M) - int(N); // in case enums are unsigned
|
||||||
register uint32 *p = state;
|
uint32 *p = state;
|
||||||
register int i;
|
int i;
|
||||||
for( i = N - M; i--; ++p )
|
for( i = N - M; i--; ++p )
|
||||||
*p = twist( p[M], p[0], p[1] );
|
*p = twist( p[M], p[0], p[1] );
|
||||||
for( i = M; --i; ++p )
|
for( i = M; --i; ++p )
|
||||||
@ -205,9 +205,9 @@ inline void MTRand::seed( uint32 *const bigSeed, const uint32 seedLength )
|
|||||||
// in each element are discarded.
|
// in each element are discarded.
|
||||||
// Just call seed() if you want to get array from /dev/urandom
|
// Just call seed() if you want to get array from /dev/urandom
|
||||||
initialize(19650218UL);
|
initialize(19650218UL);
|
||||||
register int i = 1;
|
int i = 1;
|
||||||
register uint32 j = 0;
|
uint32 j = 0;
|
||||||
register int k = ( N > seedLength ? N : seedLength );
|
int k = ( N > seedLength ? N : seedLength );
|
||||||
for( ; k; --k )
|
for( ; k; --k )
|
||||||
{
|
{
|
||||||
state[i] =
|
state[i] =
|
||||||
@ -238,7 +238,7 @@ inline void MTRand::seed()
|
|||||||
|
|
||||||
// First try getting an array from /dev/urandom
|
// First try getting an array from /dev/urandom
|
||||||
|
|
||||||
/* // Commented out by FakeTruth because doing this 200 times a tick is SUUUUPEERRR SLOW!!~~!ÕNe
|
/* // Commented out by FakeTruth because doing this 200 times a tick is SUUUUPEERRR SLOW!!~~!\D5Ne
|
||||||
FILE* urandom = fopen( "/dev/urandom", "rb" );
|
FILE* urandom = fopen( "/dev/urandom", "rb" );
|
||||||
if( urandom )
|
if( urandom )
|
||||||
{
|
{
|
||||||
@ -268,9 +268,9 @@ inline MTRand::MTRand()
|
|||||||
|
|
||||||
inline MTRand::MTRand( const MTRand& o )
|
inline MTRand::MTRand( const MTRand& o )
|
||||||
{
|
{
|
||||||
register const uint32 *t = o.state;
|
const uint32 *t = o.state;
|
||||||
register uint32 *s = state;
|
uint32 *s = state;
|
||||||
register int i = N;
|
int i = N;
|
||||||
for( ; i--; *s++ = *t++ ) {}
|
for( ; i--; *s++ = *t++ ) {}
|
||||||
left = o.left;
|
left = o.left;
|
||||||
pNext = &state[N-left];
|
pNext = &state[N-left];
|
||||||
@ -284,7 +284,7 @@ inline MTRand::uint32 MTRand::randInt()
|
|||||||
if( left == 0 ) reload();
|
if( left == 0 ) reload();
|
||||||
--left;
|
--left;
|
||||||
|
|
||||||
register uint32 s1;
|
uint32 s1;
|
||||||
s1 = *pNext++;
|
s1 = *pNext++;
|
||||||
s1 ^= (s1 >> 11);
|
s1 ^= (s1 >> 11);
|
||||||
s1 ^= (s1 << 7) & 0x9d2c5680UL;
|
s1 ^= (s1 << 7) & 0x9d2c5680UL;
|
||||||
@ -358,18 +358,18 @@ inline double MTRand::operator()()
|
|||||||
|
|
||||||
inline void MTRand::save( uint32* saveArray ) const
|
inline void MTRand::save( uint32* saveArray ) const
|
||||||
{
|
{
|
||||||
register const uint32 *s = state;
|
const uint32 *s = state;
|
||||||
register uint32 *sa = saveArray;
|
uint32 *sa = saveArray;
|
||||||
register int i = N;
|
int i = N;
|
||||||
for( ; i--; *sa++ = *s++ ) {}
|
for( ; i--; *sa++ = *s++ ) {}
|
||||||
*sa = left;
|
*sa = left;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void MTRand::load( uint32 *const loadArray )
|
inline void MTRand::load( uint32 *const loadArray )
|
||||||
{
|
{
|
||||||
register uint32 *s = state;
|
uint32 *s = state;
|
||||||
register uint32 *la = loadArray;
|
uint32 *la = loadArray;
|
||||||
register int i = N;
|
int i = N;
|
||||||
for( ; i--; *s++ = *la++ ) {}
|
for( ; i--; *s++ = *la++ ) {}
|
||||||
left = *la;
|
left = *la;
|
||||||
pNext = &state[N-left];
|
pNext = &state[N-left];
|
||||||
@ -377,16 +377,16 @@ inline void MTRand::load( uint32 *const loadArray )
|
|||||||
|
|
||||||
inline std::ostream& operator<<( std::ostream& os, const MTRand& mtrand )
|
inline std::ostream& operator<<( std::ostream& os, const MTRand& mtrand )
|
||||||
{
|
{
|
||||||
register const MTRand::uint32 *s = mtrand.state;
|
const MTRand::uint32 *s = mtrand.state;
|
||||||
register int i = mtrand.N;
|
int i = mtrand.N;
|
||||||
for( ; i--; os << *s++ << "\t" ) {}
|
for( ; i--; os << *s++ << "\t" ) {}
|
||||||
return os << mtrand.left;
|
return os << mtrand.left;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::istream& operator>>( std::istream& is, MTRand& mtrand )
|
inline std::istream& operator>>( std::istream& is, MTRand& mtrand )
|
||||||
{
|
{
|
||||||
register MTRand::uint32 *s = mtrand.state;
|
MTRand::uint32 *s = mtrand.state;
|
||||||
register int i = mtrand.N;
|
int i = mtrand.N;
|
||||||
for( ; i--; is >> *s++ ) {}
|
for( ; i--; is >> *s++ ) {}
|
||||||
is >> mtrand.left;
|
is >> mtrand.left;
|
||||||
mtrand.pNext = &mtrand.state[mtrand.N-mtrand.left];
|
mtrand.pNext = &mtrand.state[mtrand.N-mtrand.left];
|
||||||
@ -396,9 +396,9 @@ inline std::istream& operator>>( std::istream& is, MTRand& mtrand )
|
|||||||
inline MTRand& MTRand::operator=( const MTRand& o )
|
inline MTRand& MTRand::operator=( const MTRand& o )
|
||||||
{
|
{
|
||||||
if( this == &o ) return (*this);
|
if( this == &o ) return (*this);
|
||||||
register const uint32 *t = o.state;
|
const uint32 *t = o.state;
|
||||||
register uint32 *s = state;
|
uint32 *s = state;
|
||||||
register int i = N;
|
int i = N;
|
||||||
for( ; i--; *s++ = *t++ ) {}
|
for( ; i--; *s++ = *t++ ) {}
|
||||||
left = o.left;
|
left = o.left;
|
||||||
pNext = &state[N-left];
|
pNext = &state[N-left];
|
||||||
|
Loading…
Reference in New Issue
Block a user