39template <UINT32 ALPHA = (8)>
44 typedef unsigned char byte;
76 enum {
N = (1<<ALPHA)};
102template<UINT32 ALPHA>
109template<UINT32 ALPHA>
112 for(
int i = 0;
i < N;
i++)
114 m_rc.randrsl[
i] =
s != NULL ?
s[
i] : 0;
121 randinit(&m_rc,
true);
125template<UINT32 ALPHA>
128 return 0x7fffffff & (!m_rc.randcnt-- ?
129 (isaac(&m_rc), m_rc.randcnt=(N-1), m_rc.randrsl[m_rc.randcnt]) :
130 m_rc.randrsl[m_rc.randcnt]);
134template<UINT32 ALPHA>
155 shuffle(
a,
b,
c,d,e,
f,g,h);
162 for(i=0;
i < N;
i+=8)
167 shuffle(
a,
b,
c,d,e,
f,g,h);
175 for(i=0;
i < N;
i += 8)
180 shuffle(
a,
b,
c,d,e,
f,g,h);
190 shuffle(
a,
b,
c,d,e,
f,g,h);
202template<UINT32 ALPHA>
205 return (*(
UINT32*)((
byte*)(
mm) + ((x) & ((N-1)<<2))));
209template<UINT32 ALPHA>
213 a = (
a^(mix)) + *(m2++);
214 *(
m++) = y = ind(
mm,x) +
a +
b;
215 *(
r++) =
b = ind(
mm,y>>ALPHA) +
x;
219template<UINT32 ALPHA>
226 e^=
f<<10; h+=
e;
f+=
g;
233template<UINT32 ALPHA>
242 UINT32 b = (ctx->randb + (++ctx->randc));
250 rngstep((
a<<13),
a,
b,
mm, m, m2, r, x, y);
251 rngstep((
a>>6) ,
a,
b,
mm, m, m2, r, x, y);
252 rngstep((
a<<2) ,
a,
b,
mm, m, m2, r, x, y);
253 rngstep((
a>>16),
a,
b,
mm, m, m2, r, x, y);
260 rngstep((
a<<13),
a,
b,
mm, m, m2, r, x, y);
261 rngstep((
a>>6) ,
a,
b,
mm, m, m2, r, x, y);
262 rngstep((
a<<2) ,
a,
b,
mm, m, m2, r, x, y);
263 rngstep((
a>>16),
a,
b,
mm, m, m2, r, x, y);
virtual void isaac(randctx *ctx)
virtual void shuffle(UINT32 &a, UINT32 &b, UINT32 &c, UINT32 &d, UINT32 &e, UINT32 &f, UINT32 &g, UINT32 &h)
virtual void randinit(randctx *ctx, bool bUseSeed)
virtual void isaac(randctx *ctx)
void rngstep(UINT32 mix, UINT32 &a, UINT32 &b, UINT32 *&mm, UINT32 *&m, UINT32 *&m2, UINT32 *&r, UINT32 &x, UINT32 &y)
UINT32 ind(UINT32 *mm, UINT32 x)
virtual void srand(UINT32 a=0, UINT32 b=0, UINT32 c=0, UINT32 *s=NULL)
QTIsaac(UINT32 a=0, UINT32 b=0, UINT32 c=0)
virtual void randinit(randctx *ctx, bool bUseSeed)
virtual void shuffle(UINT32 &a, UINT32 &b, UINT32 &c, UINT32 &d, UINT32 &e, UINT32 &f, UINT32 &g, UINT32 &h)
virtual void srand(UINT32 a=0, UINT32 b=0, UINT32 c=0, UINT32 *s=NULL)
const UINT32 GOLDEN_RATIO