#include <stddef.h>
#include <stdint.h>
#define N 4
#define M (N-1)
#define SEQ_LEN (1u<<27)
static const unsigned char rule[16] = {
1, 1, 0, 1, // B
0, 0, 0, 1, // 8
0, 0, 1, 0, // 4
1, 1, 1, 0 // 7
}; // 0x748B
static uint8_t q[N][N][N];
static void InitRng(uint64_t seed)
{
int x, y, z;
for (z = 0; z <= M; z++)
for (y = 0; y <= M; y++)
for (x = 0; x <= M; x++)
{
q[z][y][x] = (uint8_t) (seed & 1);
seed >>= 1;
}
}
static uint64_t UpdateRng(int osr)
{
uint8_t p[N][N][N];
int x, y, z;
uint64_t r = 0;
while(--osr >= 0)
{
for (z = 0; z <= M; z++)
{
for (y = 0; y <= M; y++)
for (x = 0; x <= M; x++)
{
int i = 0;
i |= q[(z + 1) & M][(y + 1) & M][(x + 1) & M] ? 1 : 0;
i |= q[(z + 1) & M][(y - 1) & M][(x + 0) & M] ? 2 : 0;
i |= q[(z + 0) & M][(y + 0) & M][(x + 0) & M] ? 4 : 0;
i |= q[(z - 1) & M][(y + 0) & M][(x - 1) & M] ? 8 : 0;
p[z][y][x] = rule[i];
}
}
for (z = M; z >= 0; z--)
for (y = M; y >= 0; y--)
for (x = M; x >= 0; x--)
{
q[z][y][x] = p[z][y][x];
if (osr == 0)
r = (r << 1) | (q[z][y][x] ? 1 : 0);
}
}
return r;
}
int rpdf32(int npt, int osr, double scl, double *y)
{
int n, k;
int32_t ii;
union
{
uint64_t v;
uint32_t u[2];
} r;
uint64_t r0 = 0x86d0d2bcc74b5415;
for (n = SEQ_LEN / osr; npt > 0; npt -= n)
{
n = npt > n ? n : npt;
InitRng(r0);
for (k = 0; k < n; k++)
{
r.v = UpdateRng(osr);
ii = (int32_t) (r.u[0] ^ r.u[1]);
*y++ = scl * ii;
}
}
return 0;
}
/* EOF */
[свернуть]
Социальные закладки