added skip8 method
This commit is contained in:
parent
b79d034950
commit
21704994bf
|
|
@ -28,6 +28,8 @@ Version NEXT
|
|||
randomcheck: ability to run group tests with different seeds
|
||||
this will more balance results to be less initial seed
|
||||
dependant. classic fsp algo seems to produce best results.
|
||||
randomcheck: added skip8 method. skips 8 lowest bits from
|
||||
random() output
|
||||
|
||||
Version 2.8.1b29 - 24 Aug 2019
|
||||
added scons command line argument without-fspscan=yes for building
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
#include "my-string.h"
|
||||
#include <math.h>
|
||||
|
||||
static int group[4];
|
||||
#define GROUPS 5
|
||||
static int group[GROUPS];
|
||||
static int bitcount[16];
|
||||
static int rounds;
|
||||
static int groups;
|
||||
|
|
@ -46,6 +47,10 @@ static unsigned short simple2 (void)
|
|||
/* we assume that our return value is 16 bits long
|
||||
and random() returns only positive long integers
|
||||
*/
|
||||
/* TODO: this needs to be checked on 64-bit systems because
|
||||
I am not sure if random returns 31 bits or 63 bits of
|
||||
randomness there.
|
||||
*/
|
||||
return ( random() >> (SIZEOF_LONG*8 - 16 - 1) );
|
||||
}
|
||||
|
||||
|
|
@ -57,6 +62,13 @@ static unsigned short nr(void)
|
|||
return(ulRandom);
|
||||
}
|
||||
|
||||
/* Skip lowest 8 bits */
|
||||
static unsigned short skip8(void)
|
||||
{
|
||||
long randomValue = random();
|
||||
return randomValue >> 8;
|
||||
}
|
||||
|
||||
static void run_randomtest( unsigned short (*keygen)(void) )
|
||||
{
|
||||
int i,j;
|
||||
|
|
@ -118,7 +130,7 @@ static float worst_bitcount(void)
|
|||
|
||||
static void run_one(void)
|
||||
{
|
||||
float worst[4];
|
||||
float worst[GROUPS];
|
||||
memset(worst, 0, sizeof(worst));
|
||||
|
||||
run_randomtest(classic);
|
||||
|
|
@ -133,11 +145,14 @@ static void run_one(void)
|
|||
run_randomtest(nr);
|
||||
worst[3] = worst_bitcount();
|
||||
|
||||
run_randomtest(skip8);
|
||||
worst[4] = worst_bitcount();
|
||||
|
||||
/* fimd the best algo */
|
||||
float minValue = worst[0];
|
||||
int minIndex = 0;
|
||||
|
||||
for (int i = 1; i < 4; i++)
|
||||
for (int i = 1; i < GROUPS; i++)
|
||||
{
|
||||
if (worst[i] < minValue)
|
||||
{
|
||||
|
|
@ -209,6 +224,7 @@ int main(int argc,const char *argv[])
|
|||
printf("Generator: simple (low bits) %d\n", group[1]);
|
||||
printf("Generator: simple2 (high bits) %d\n", group[2]);
|
||||
printf("Generator: Numerical Recipes %d\n", group[3]);
|
||||
printf("Generator: skip8 (skip 8 lower bits) %d\n", group[4]);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user