add simple15 shift to randomize tests
This commit is contained in:
parent
ca1abea3ea
commit
848368274c
|
|
@ -30,6 +30,8 @@ Version NEXT
|
||||||
dependant. classic fsp algo seems to produce best results.
|
dependant. classic fsp algo seems to produce best results.
|
||||||
randomcheck: added skip8 method. skips 8 lowest bits from
|
randomcheck: added skip8 method. skips 8 lowest bits from
|
||||||
random() output
|
random() output
|
||||||
|
randomcheck: added simple15 method. its currently used random
|
||||||
|
number generator in 2.8.1 beta 29 code
|
||||||
|
|
||||||
Version 2.8.1b29 - 24 Aug 2019
|
Version 2.8.1b29 - 24 Aug 2019
|
||||||
added scons command line argument without-fspscan=yes for building
|
added scons command line argument without-fspscan=yes for building
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#include "my-string.h"
|
#include "my-string.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#define GROUPS 5
|
#define GROUPS 6
|
||||||
static int group[GROUPS];
|
static int group[GROUPS];
|
||||||
static int bitcount[16];
|
static int bitcount[16];
|
||||||
static int rounds;
|
static int rounds;
|
||||||
|
|
@ -35,6 +35,15 @@ static unsigned short simple (void)
|
||||||
return random();
|
return random();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
shift random() 15 times to get higher bits.
|
||||||
|
used in fsp beta 29 as production random code.
|
||||||
|
*/
|
||||||
|
static unsigned short simple15 (void)
|
||||||
|
{
|
||||||
|
return ( random() >> 15 );
|
||||||
|
}
|
||||||
|
|
||||||
/* get high bits from random() result.
|
/* get high bits from random() result.
|
||||||
|
|
||||||
In most classic random implementations used in libc
|
In most classic random implementations used in libc
|
||||||
|
|
@ -45,11 +54,16 @@ In modern random() generators there should be no difference.
|
||||||
static unsigned short simple2 (void)
|
static unsigned short simple2 (void)
|
||||||
{
|
{
|
||||||
/* we assume that our return value is 16 bits long
|
/* we assume that our return value is 16 bits long
|
||||||
and random() returns only positive long integers
|
and random() returns only positive long integers.
|
||||||
|
Original code used >> 15
|
||||||
*/
|
*/
|
||||||
/* TODO: this needs to be checked on 64-bit systems because
|
/* TODO: this needs to be checked on 64-bit systems because
|
||||||
I am not sure if random returns 31 bits or 63 bits of
|
I am not sure if random returns 31 bits or 63 bits of
|
||||||
randomness there.
|
randomness there.
|
||||||
|
|
||||||
|
Current status:
|
||||||
|
32-bit: 17 shifts
|
||||||
|
64-bit: 49 shifts
|
||||||
*/
|
*/
|
||||||
return ( random() >> (SIZEOF_LONG*8 - 16 - 1) );
|
return ( random() >> (SIZEOF_LONG*8 - 16 - 1) );
|
||||||
}
|
}
|
||||||
|
|
@ -148,6 +162,9 @@ static void run_one(void)
|
||||||
run_randomtest(skip8);
|
run_randomtest(skip8);
|
||||||
worst[4] = worst_bitcount();
|
worst[4] = worst_bitcount();
|
||||||
|
|
||||||
|
run_randomtest(simple15);
|
||||||
|
worst[5] = worst_bitcount();
|
||||||
|
|
||||||
/* fimd the best algo */
|
/* fimd the best algo */
|
||||||
float minValue = worst[0];
|
float minValue = worst[0];
|
||||||
int minIndex = 0;
|
int minIndex = 0;
|
||||||
|
|
@ -208,9 +225,17 @@ int main(int argc,const char *argv[])
|
||||||
run_randomtest(simple2);
|
run_randomtest(simple2);
|
||||||
print_bitcount();
|
print_bitcount();
|
||||||
|
|
||||||
|
printf("Generator: simple15 (high bits legacy)\n");
|
||||||
|
run_randomtest(simple15);
|
||||||
|
print_bitcount();
|
||||||
|
|
||||||
printf("Generator: Numerical Recipes\n");
|
printf("Generator: Numerical Recipes\n");
|
||||||
run_randomtest(nr);
|
run_randomtest(nr);
|
||||||
print_bitcount();
|
print_bitcount();
|
||||||
|
|
||||||
|
printf("Generator: skip8\n");
|
||||||
|
run_randomtest(skip8);
|
||||||
|
print_bitcount();
|
||||||
} else {
|
} else {
|
||||||
int i;
|
int i;
|
||||||
for (i=0; i< groups; i++)
|
for (i=0; i< groups; i++)
|
||||||
|
|
@ -219,10 +244,11 @@ int main(int argc,const char *argv[])
|
||||||
run_one();
|
run_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Winning generators\n\n");
|
printf("Winning generators:\n\n");
|
||||||
printf("Generator: classic %d\n", group[0]);
|
printf("Generator: classic %d\n", group[0]);
|
||||||
printf("Generator: simple (low bits) %d\n", group[1]);
|
printf("Generator: simple (low bits) %d\n", group[1]);
|
||||||
printf("Generator: simple2 (high bits) %d\n", group[2]);
|
printf("Generator: simple2 (high bits) %d\n", group[2]);
|
||||||
|
printf("Generator: simple15 (shift by 15) %d\n", group[5]);
|
||||||
printf("Generator: Numerical Recipes %d\n", group[3]);
|
printf("Generator: Numerical Recipes %d\n", group[3]);
|
||||||
printf("Generator: skip8 (skip 8 lower bits) %d\n", group[4]);
|
printf("Generator: skip8 (skip 8 lower bits) %d\n", group[4]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user