#include <soar_rand.h>
Static Protected Member Functions |
static uint32_t | hash (time_t t, clock_t c) |
Detailed Description
Definition at line 91 of file soar_rand.h.
Member Enumeration Documentation
Constructor & Destructor Documentation
MTRand::MTRand |
( |
const uint32_t & |
oneSeed | ) |
|
|
inline |
Member Function Documentation
uint32_t MTRand::hash |
( |
time_t |
t, |
|
|
clock_t |
c |
|
) |
| |
|
inlinestaticprotected |
Definition at line 346 of file soar_rand.h.
References uint32_t().
Referenced by seed().
{
unsigned char *p = (unsigned char *) &t;
for( size_t i = 0; i < sizeof(t); ++i )
{
h1 *= UCHAR_MAX + 2U;
h1 += p[i];
}
p = (unsigned char *) &c;
for( size_t j = 0; j < sizeof(c); ++j )
{
h2 *= UCHAR_MAX + 2U;
h2 += p[j];
}
return ( h1 + differ++ ) ^ h2;
}
void MTRand::initialize |
( |
const uint32_t |
oneSeed | ) |
|
|
inlineprotected |
Definition at line 312 of file soar_rand.h.
References N, state, and uint32_t().
Referenced by seed().
{
register int i = 1;
*s++ =
seed & 0xffffffffU;
{
*s++ = ( 1812433253U * ( *r ^ (*r >> 30) ) + i ) & 0xffffffffU;
r++;
}
}
void MTRand::load |
( |
uint32_t *const |
loadArray | ) |
|
|
inline |
double MTRand::operator() |
( |
| ) |
|
|
inline |
double MTRand::rand |
( |
const double & |
n | ) |
|
|
inline |
double MTRand::rand53 |
( |
| ) |
|
|
inline |
double MTRand::randDblExc |
( |
| ) |
|
|
inline |
double MTRand::randDblExc |
( |
const double & |
n | ) |
|
|
inline |
double MTRand::randExc |
( |
| ) |
|
|
inline |
double MTRand::randExc |
( |
const double & |
n | ) |
|
|
inline |
Definition at line 223 of file soar_rand.h.
References randInt(), and uint32_t().
{
used |= used >> 1;
used |= used >> 2;
used |= used >> 4;
used |= used >> 8;
used |= used >> 16;
do
while( i > n );
return i;
}
double MTRand::randNorm |
( |
const double & |
mean = 0.0 , |
|
|
const double & |
stddeviation = 0.0 |
|
) |
| |
|
inline |
Definition at line 330 of file soar_rand.h.
References left, M, N, pNext, state, twist(), and uint32_t().
Referenced by randInt(), and seed().
{
register int i;
for( i =
N -
M; i--; ++p )
*p =
twist( p[
M], p[0], p[1] );
for( i = M; --i; ++p )
*p =
twist( p[M-
N], p[0], p[1] );
}
void MTRand::save |
( |
uint32_t * |
saveArray | ) |
const |
|
inline |
void MTRand::seed |
( |
const uint32_t |
oneSeed | ) |
|
|
inline |
Definition at line 251 of file soar_rand.h.
References initialize(), N, reload(), state, and uint32_t().
{
register int i = 1;
register int k = (
N > seedLength ?
N : seedLength );
for( ; k; --k )
{
state[i] += ( bigSeed[j] & 0xffffffffU ) + j;
state[i] &= 0xffffffffU;
++i; ++j;
if( i >=
N ) { state[0] = state[
N-1]; i = 1; }
if( j >= seedLength ) j = 0;
}
{
state[i] =
state[i] ^ ( (state[i-1] ^ (state[i-1] >> 30)) * 1566083941U );
state[i] -= i;
state[i] &= 0xffffffffU;
++i;
if( i >=
N ) { state[0] = state[
N-1]; i = 1; }
}
state[0] = 0x80000000U;
}
Definition at line 287 of file soar_rand.h.
References hash(), N, and uint32_t().
Referenced by MTRand().
{
FILE* urandom = fopen( "/dev/urandom", "rb" );
if( urandom )
{
register bool success = true;
while( success && i-- )
success = (fread( s++,
sizeof(
uint32_t), 1, urandom ) == 0);
fclose(urandom);
if( success ) {
seed( bigSeed,
N );
return; }
}
}
Friends And Related Function Documentation
std::ostream& operator<< |
( |
std::ostream & |
os, |
|
|
const MTRand & |
mtrand |
|
) |
| |
|
friend |
Definition at line 393 of file soar_rand.h.
{
register int i = mtrand.
N;
for( ; i--; os << *s++ << "\t" ) {}
return os << mtrand.
left;
}
std::istream& operator>> |
( |
std::istream & |
is, |
|
|
MTRand & |
mtrand |
|
) |
| |
|
friend |
Definition at line 402 of file soar_rand.h.
{
register int i = mtrand.
N;
for( ; i--; is >> *s++ ) {}
return is;
}
Field Documentation
The documentation for this class was generated from the following file: