新人求问,这组代码是用来产生随机数的吗?求大神解释
#define MBIG 1000000000#define MSEED 161803398
#define MZ 0
#define FAC 1.0E-9
double CMCMie::RandomGen(char Type, long Seed, long *Status)
{
static long i1, i2, ma[56]; /* ma[0] is not used. */
long mj, mk;
short i, ii;
if (Type == 0) { /* set seed. */
mj = MSEED - (Seed < 0 ? -Seed : Seed);
mj %= MBIG;
ma[55] = mj;
mk = 1;
for (i = 1; i <= 54; i++)
{
ii = (21 * i) % 55;
ma[ii] = mk;
mk = mj - mk;
if (mk < MZ)
mk += MBIG;
mj = ma[ii];
}
for (ii = 1; ii <= 4; ii++)
for (i = 1; i <= 55; i++) {
ma[i] -= ma[1 + (i + 30) % 55];
if (ma[i] < MZ)
ma[i] += MBIG;
}
i1 = 0;
i2 = 31;
} else if (Type == 1) { /* get a number. */
if (++i1 == 56)
i1 = 1;
if (++i2 == 56)
i2 = 1;
mj = ma[i1] - ma[i2];
if (mj < MZ)
mj += MBIG;
ma[i1] = mj;
return (mj * FAC);
} else if (Type == 2) { /* get status. */
for (i = 0; i < 55; i++)
Status[i] = ma[i + 1];
Status[55] = i1;
Status[56] = i2;
} else if (Type == 3) { /* restore status. */
for (i = 0; i < 55; i++)
ma[i + 1] = Status[i];
i1 = Status[55];
i2 = Status[56];
} else
AfxMessageBox(_T("Wrong parameter to RandomGen()."));
return (0);