Skip to content

Instantly share code, notes, and snippets.

@preshing
Created December 24, 2012 04:07
Show Gist options
  • Save preshing/4367443 to your computer and use it in GitHub Desktop.
Save preshing/4367443 to your computer and use it in GitHub Desktop.
A C++ source file to test the RandomSequenceOfUnique random number generator using TestU01's SmallCrush test suite.
#include "randomsequence.h"
#include <stdio.h>
#include <string.h>
extern "C"
{
#include "unif01.h"
#include "bbattery.h"
#include "util.h"
}
#define LEN 300 /* Max length of strings */
static void WrRSU (void *vsta)
{
printf (" (unimplemented)\n");
}
static double RSU_U01 (void *vpar, void *vsta)
{
RandomSequenceOfUnique *rsu = (RandomSequenceOfUnique*) vsta;
return rsu->next() / 4294967296.0;
}
static unsigned long RSU_Bits (void *vpar, void *vsta)
{
RandomSequenceOfUnique *rsu = (RandomSequenceOfUnique*) vsta;
return rsu->next();
}
unif01_Gen *ursu_CreateRSU (unsigned int seedBase, unsigned int seedOffset)
{
unif01_Gen *gen = (unif01_Gen*) util_Malloc (sizeof (unif01_Gen));
RandomSequenceOfUnique *rsu = new RandomSequenceOfUnique(seedBase, seedOffset);
size_t leng;
char name[LEN + 1];
sprintf(name, "ursu_CreateRSU: seedBase = %d, seedOffset = %d", seedBase, seedOffset);
leng = strlen (name);
gen->name = (char*) util_Calloc (leng + 1, sizeof (char));
strncpy (gen->name, name, leng);
gen->param = NULL;
gen->state = rsu;
gen->Write = &WrRSU;
gen->GetBits = &RSU_Bits;
gen->GetU01 = &RSU_U01;
return gen;
}
void ursu_DeleteGen (unif01_Gen *gen)
{
if (NULL == gen) return;
delete (RandomSequenceOfUnique*) gen->state;
gen->name = (char*) util_Free (gen->name);
util_Free (gen);
}
int main (void)
{
unif01_Gen *gen;
gen = ursu_CreateRSU (0, 0);
bbattery_SmallCrush(gen);
ursu_DeleteGen (gen);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment