
Сообщение от
capzap
опять же не показана реализация флоата в oscat_next, маска из трех или четырех байт, если сделано по анологии с xorshift тогда теряется некоторая часть случайных значений и вряд ли будут пройдены тесты
Вот код rdm. Тесты НЕ проходит.
Код:
unsigned int bit_count(unsigned int n) {
unsigned int c;
for (c=0;n>0;n=n&(n-1)) c++;
return c;
}
unsigned int rol(unsigned int x, unsigned int n){
return (x << n)|(x >> (32-n));
}
void rdm()
{
int i, counter;
unsigned bit;
int num_0s, num_1s, v, bitsRead;
unsigned char x = 42;
unsigned char mask;
unsigned int T_PLC_MS = 7*24*3600*1000;
unsigned int tn;
unsigned int tc;
float m;
float rx;
float rdm;
float last;
float E = exp(1.0);
if ( ((epsilon = (BitSequence *) calloc(tp.n, sizeof(BitSequence))) == NULL) ) {
printf("Insufficient memory available.\n");
exit(1);
}
counter = 1;
last = 42;
for ( v=0; v < tp.numOfBitStreams; v++ ) {
mask = 0;
num_0s = 0;
num_1s = 0;
bitsRead = 0;
for ( i=0; i < tp.n; i++ ) {
// if (mask == 0) {
mask = 0x800000;
tn = clock() * 1000.0/ CLOCKS_PER_SEC;
tc = bit_count(tn);
tn |= (tn&(1 << (2))) << (31-2);
tn |= (tn&(1 << (5))) << (30-5);
tn |= (tn&(1 << (4))) << (29-4);
tn |= (tn&(1 << (1))) << (28-1);
tn |= (tn&(1 << (0))) << (27-0);
tn |= (tn&(1 << (7))) << (26-7);
tn |= (tn&(1 << (6))) << (25-6);
tn |= (tn&(1 << (3))) << (24-3);
tn = rol(tn, bit_count(tn)) | 0x80000001;
tn = tn % 71474513 + (tc + 77);
rdm = ((float)tn) / 10000000.0 * (E - (last < 0.0 ? 0 : (last > 1.0?1.0:last) ));
rdm = rdm - floor(rdm);
last = rdm;
// T_PLC_MS+=10;
// }
if ( rdm < 0.5 ) {//(x & mask) == 0 ) {
bit = 0;
num_0s++;
}
else {
bit = 1;
num_1s++;
}
mask /= 2;
bitsRead++;
epsilon[i] = bit;
}
fprintf(freqfp, "\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); fflush(freqfp);
nist_test_suite();
}
free(epsilon);
}
Вот код xorshift128, тесты проходит (все, кроме теста LinearComplexity) (проходит как в варианте float 0..1, так и в варианте когда учитываем все 32 бита):
Код:
void
xorshift128()
{
int i, counter;
unsigned bit;
int num_0s, num_1s, v, bitsRead;
unsigned int res;
unsigned int mask;
unsigned int x = 123456789;
unsigned int y = 362436069;
unsigned int z = 521288629;
unsigned int w = 88675123;
if ( ((epsilon = (BitSequence *) calloc(tp.n, sizeof(BitSequence))) == NULL) ) {
printf("Insufficient memory available.\n");
exit(1);
}
counter = 1;
for ( v=0; v < tp.numOfBitStreams; v++ ) {
mask = 0;
num_0s = 0;
num_1s = 0;
bitsRead = 0;
for ( i=0; i < tp.n; i++ ) {
// if (mask == 0) {
mask = 0x80000000;
unsigned int t = x ^ (x << 11);
x = y; y = z; z = w;
w ^= (w >> 19) ^ t ^ (t >> 8);
res = w;
/* fprintf(freqfp, "value =
\n", res);
if (v > 1024) {
exit(-1);
}*/
// }
// if ( (res & mask) == 0 ) {
if ( (res&16777215)/16777216.0 < 0.5 ) {
bit = 0;
num_0s++;
}
else {
bit = 1;
num_1s++;
}
mask /= 2;
bitsRead++;
epsilon[i] = bit;
}
fprintf(freqfp, "\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); fflush(freqfp);
nist_test_suite();
}
free(epsilon);
}
Что на этот раз?