Ejemplo n.º 1
0
unif01_Gen * unumrec_CreateRan0 (long s)
{
   unif01_Gen *gen;
   Ran0_param *param;
   Ran0_state *state;
   size_t leng;
   char name[LEN + 1];

   util_Assert (s > 0, "unumrec_CreateRan0:   s <= 0");

   gen = util_Malloc (sizeof (unif01_Gen));
   param = util_Malloc (sizeof (Ran0_param));
   state = util_Malloc (sizeof (Ran0_state));

   strncpy (name, "unumrec_CreateRan0:", LEN);
   addstr_Long (name, "   s = ", s);
   leng = strlen (name);
   gen->name = util_Calloc (leng + 1, sizeof (char));
   strncpy (gen->name, name, leng);

   state->S1 = s;
   param->Norm = 1.0 / M1;

   gen->GetBits = &Ran0_Bits;
   gen->GetU01  = &Ran0_U01;
   gen->Write   = &WrRan0;
   gen->param   = param;
   gen->state   = state;
   return gen;
}
Ejemplo n.º 2
0
unif01_Gen *uweyl_CreateSNWeyl (long M, double Alpha, long n0)
{
   unif01_Gen *gen;
   SNWeyl_param *param;
   Weyl_state *state;
   size_t leng;
   char name[LEN + 1];

   util_Assert ((Alpha > 0.0), "uweyl_CreateSNWeyl:   Alpha <= 0");
   util_Assert ((Alpha < 1.0), "uweyl_CreateSNWeyl:   Alpha >= 1");

   gen = util_Malloc (sizeof (unif01_Gen));
   param = util_Malloc (sizeof (SNWeyl_param));
   state = util_Malloc (sizeof (Weyl_state));
   param->Alpha = Alpha;
   param->M = M;
   if (n0 < 0)
      n0 = -n0;
   state->n = n0;

   strncpy (name, "uweyl_CreateSNWeyl (shuffled nested):", (size_t) LEN);
   addstr_Long (name, "   M = ", M);
   addstr_Double (name, ",   Alpha = ", Alpha);
   addstr_Long (name, ",   n0 = ", n0);
   leng = strlen (name);
   gen->name = util_Calloc (leng + 1, sizeof (char));
   strncpy (gen->name, name, leng);

   gen->GetBits = &SNWeyl_Bits;
   gen->GetU01  = &SNWeyl_U01;
   gen->Write   = &WrWeyl;
   gen->param   = param;
   gen->state   = state;
   return gen;
}
Ejemplo n.º 3
0
fcho_Cho * fcho_CreateSampleSize (double a, double b, double c,
                                  fcho_FuncType F, char *name)
{
   fcho_Cho *cho;
   Sample_Param *param;   
   size_t len;
   char *name0 = "n";

   cho = (fcho_Cho*)util_Malloc (sizeof (fcho_Cho));
   param = (Sample_Param*)util_Malloc (sizeof (Sample_Param));
   param->a = a;
   param->b = b;
   param->c = c;
   if (NULL == F)
      param->F = fcho_2Pow;
   else
      param->F = F;

   if (NULL == name)
      name = name0;
   len = strlen (name);
   cho->name = (char*)util_Calloc (len + 1, sizeof (char));
   strncpy (cho->name, name, (size_t) len);
   cho->param = param;
   cho->Write = WriteSample;
   cho->Choose = ChooseSample;
   param->name = cho->name;
   return cho;
}
Ejemplo n.º 4
0
static unif01_Gen *CreateDenga (unsigned long m, unsigned long b, int k,
   unsigned long S[], int id)
{
   unif01_Gen *gen;
   DX02_state *state;
   DX02_param *param;
   size_t leng;
   char name[LEN + 1];
   int j;

   gen = util_Malloc (sizeof (unif01_Gen));
   state = util_Malloc (sizeof (DX02_state));
   param = util_Malloc (sizeof (DX02_param));
   if (0 == id) {
      util_Assert (k < 129, "udeng_CreateDL00a:   k > 128");
   } else {
      util_Assert (k < 129, "udeng_CreateDX02a:   k > 128");
   }

   state->X = util_Calloc (MASK1 + 1, sizeof (double));
   for (j = 0; j < k; j++)
      state->X[k - j - 1] = S[j] % m;
   state->s = k - 1;
   state->K = k;
   param->b = b;
   param->m = m;

   if (0 == id)
      strcpy (name, "udeng_CreateDL00a:");
   else
#ifdef LAC
      strcpy (name, "udeng_CreateDX02a, Lac = {0, 101, 102}:");
#else
      strcpy (name, "udeng_CreateDX02a:");
#endif
   addstr_Ulong (name, "   m = ", m);
   addstr_Ulong (name, ",   b = ", b);
   addstr_Uint (name, ",   k = ", (unsigned) k);
   addstr_ArrayUlong (name, ",   S = ", k, S);
   leng = strlen (name);
   gen->name = util_Calloc (leng + 1, sizeof (char));
   strncpy (gen->name, name, leng);

   gen->param   = param;
   gen->state   = state;
   if (0 == id) {
      gen->GetBits = &DL00a_Bits;
      gen->GetU01  = &DL00a_U01;
   } else {
      gen->GetBits = &DX02a_Bits;
      gen->GetU01  = &DX02a_U01;
   }
   gen->Write   = &WrDX02a;
   return gen;
}
Ejemplo n.º 5
0
unif01_Gen * utaus_CreateLongTaus (unsigned int k, unsigned int q,
                                   unsigned int s, ulonglong Y)
{
   unif01_Gen *gen;
   LongTaus_param *param;
   LongTaus_state *state;
   size_t len;
   char name[LEN0 + 1];
   ulonglong B;

   util_Assert ((k <= 64) && (k > 2 * q) && (s <= k - q) && (s >= 1) &&
      (q >= 1), "utaus_CreateLongTaus:   Invalid Parameter");

   gen   = util_Malloc (sizeof (unif01_Gen));
   param = util_Malloc (sizeof (LongTaus_param));
   state = util_Malloc (sizeof (LongTaus_state));

   strncpy (name, "utaus_CreateLongTaus", (size_t) LEN0);
   addstr_Uint (name, ":   k = ", k);
   addstr_Uint (name, ",  q = ", q);
   addstr_Uint (name, ",  s = ", s);
   addstr_ULONG (name, ",  Y = ", Y);
   len = strlen (name);
   gen->name = util_Calloc (len + 1, sizeof (char));
   strncpy (gen->name, name, len);

   param->Q1 = q;
   param->K1mS1 = k - s;
   param->S1 = s;
   B = num_TwoExp[64 - k] - 1.0;        /* k most signif. bits at 1 */
   param->M1 = ~B;

   util_Assert (Y > 0, "utaus_CreateLongTaus:   Y = 0");
   state->ST1 = Y & param->M1;

   /* make sure that the initial state is not 0 */
   while (state->ST1 == 0) {
      Y *= 2;
      state->ST1 = Y & param->M1;
   }
   B = ((state->ST1 << param->Q1) ^ state->ST1) >> k;
   state->ST1 ^= B;

   gen->GetBits = &LongTaus_Bits;
   gen->GetU01  = &LongTaus_U01;
   gen->Write   = &WrLongTaus;
   gen->param   = param;
   gen->state   = state;
   return gen;
}
Ejemplo n.º 6
0
bool files_init(honggfuzz_t * hfuzz)
{
    hfuzz->files = util_Malloc(sizeof(char *));
    hfuzz->files[0] = "NONE";
    hfuzz->fileCnt = 1;

    if (hfuzz->externalCommand) {
        LOG_I
            ("No input file corpus loaded, the external command '%s' is responsible for creating the fuzz files",
             hfuzz->externalCommand);
        return true;
    }

    if (!hfuzz->inputDir) {
        LOG_W("No input file/dir specified");
        return false;
    }

    struct stat st;
    if (stat(hfuzz->inputDir, &st) == -1) {
        PLOG_W("Couldn't stat the input dir '%s'", hfuzz->inputDir);
        return false;
    }

    if (S_ISDIR(st.st_mode)) {
        return files_readdir(hfuzz);
    }

    LOG_W("The initial corpus directory '%s' is not a directory", hfuzz->inputDir);
    return false;
}
Ejemplo n.º 7
0
bool files_parseDictionary(honggfuzz_t * hfuzz)
{
    FILE *fDict = fopen(hfuzz->dictionaryFile, "rb");
    if (fDict == NULL) {
        PLOG_W("Couldn't open '%s' - R/O mode", hfuzz->dictionaryFile);
        return false;
    }
    defer {
        fclose(fDict);
    };

    for (;;) {
        char *lineptr = NULL;
        size_t n = 0;
        ssize_t len = getdelim(&lineptr, &n, '\n', fDict);
        if (len == -1) {
            break;
        }
        if (n > 1 && lineptr[len - 1] == '\n') {
            lineptr[len - 1] = '\0';
            len--;
        }

        struct strings_t *str = (struct strings_t *)util_Malloc(sizeof(struct strings_t));
        str->len = util_decodeCString(lineptr);
        str->s = lineptr;
        hfuzz->dictionaryCnt += 1;
        TAILQ_INSERT_TAIL(&hfuzz->dictionaryq, str, pointers);

        LOG_D("Dictionary: loaded word: '%s' (len=%zu)", str->s, str->len);
    }
    LOG_I("Loaded %zu words from the dictionary", hfuzz->dictionaryCnt);
    return true;
}
Ejemplo n.º 8
0
static bool arch_bfdInit(pid_t pid, bfd_t * bfdParams)
{
    char fname[PATH_MAX];
    snprintf(fname, sizeof(fname), "/proc/%d/exe", pid);
    if ((bfdParams->bfdh = bfd_openr(fname, 0)) == NULL) {
        LOG_E("bfd_openr(%s) failed", fname);
        return false;
    }

    if (!bfd_check_format(bfdParams->bfdh, bfd_object)) {
        LOG_E("bfd_check_format() failed");
        return false;
    }

    int storage_needed = bfd_get_symtab_upper_bound(bfdParams->bfdh);
    if (storage_needed <= 0) {
        LOG_E("bfd_get_symtab_upper_bound() returned '%d'", storage_needed);
        return false;
    }

    bfdParams->syms = (asymbol **) util_Malloc(storage_needed);
    bfd_canonicalize_symtab(bfdParams->bfdh, bfdParams->syms);

    if ((bfdParams->section = bfd_get_section_by_name(bfdParams->bfdh, ".text")) == NULL) {
        LOG_E("bfd_get_section_by_name('.text') failed");
        return false;
    }

    return true;
}
Ejemplo n.º 9
0
sknuth_Res1 * sknuth_CreateRes1 (void)
{
   sknuth_Res1 *res;
   res = util_Malloc (sizeof (sknuth_Res1));
   res->Bas = sres_CreateBasic ();
   res->Chi = sres_CreateChi2 ();
   return res;
}
Ejemplo n.º 10
0
fcho_Cho2 * fcho_CreateCho2 (fcho_Cho *Chon, fcho_Cho *Chop2)
{
   fcho_Cho2 *cho;
   cho = (fcho_Cho2*)util_Malloc (sizeof (fcho_Cho2));
   memset (cho, 0, sizeof (fcho_Cho2));
   cho->Chon = Chon;
   cho->Chop2 = Chop2;
   return cho;
}
Ejemplo n.º 11
0
sres_Poisson * sres_CreatePoisson (void)
{
   sres_Poisson *res;
   res = (sres_Poisson*)util_Malloc (sizeof (sres_Poisson));
   memset (res, 0, sizeof (sres_Poisson));
   res->sVal1 = statcoll_Create (1, "");
   res->name = (char*)util_Calloc (1, sizeof (char));
   return res;
}
Ejemplo n.º 12
0
sres_Disc * sres_CreateDisc (void)
{
   sres_Disc *res;
   res = (sres_Disc *)util_Malloc (sizeof (sres_Disc));
   memset (res, 0, sizeof (sres_Disc));
   res->sVal1 = statcoll_Create (1, "");
   res->name = (char*)util_Calloc (1, sizeof (char));
   return res;
}
Ejemplo n.º 13
0
sspectral_Res * sspectral_CreateRes (void)
{
   sspectral_Res *res;
   res = util_Malloc (sizeof (sspectral_Res));
   res->Bas = sres_CreateBasic ();
   res->Coef = util_Calloc (1, sizeof (double));
   res->jmax = 0;
   return res;
}
Ejemplo n.º 14
0
sres_Basic *sres_CreateBasic (void)
{
    sres_Basic *res;
    res = util_Malloc (sizeof (sres_Basic));
    memset (res, 0, sizeof (sres_Basic));
    res->sVal1 = statcoll_Create (1, "");
    res->pVal1 = statcoll_Create (1, "");
    res->name = util_Calloc (1, sizeof (char));
    return res;
}
Ejemplo n.º 15
0
sknuth_Res2 * sknuth_CreateRes2 (void)
{
   sknuth_Res2 *res;
   res = util_Malloc (sizeof (sknuth_Res2));
   res->Bas = sres_CreateBasic ();
   res->Pois = sres_CreatePoisson ();
   res->Pois->pLeft = -1.0;
   res->Pois->pRight = -1.0;
   return res;
}
Ejemplo n.º 16
0
unif01_Gen* CreateCombGenAPRNGFill (APRNG_t *A, unif01_Gen **g, size_t size, unsigned int fill_frequency, char *mess, char *name)
{
    unif01_Gen *gen;
    unif01_Comb_APRNG_fill_t *paramC;
    size_t len, L, i;

    gen = util_Malloc (sizeof (unif01_Gen));
    paramC = util_Malloc (sizeof (unif01_Comb_APRNG_fill_t));
    paramC->size = size;;
    paramC->g = g;
    paramC->A = A;
    paramC->fill_frequency = fill_frequency;
    paramC->n_after_fill = 0;

    len = strlen (A->name) + strlen (name) + strlen (mess);
    for (i=0; i<size; ++i) {
        len += strlen (g[i]->name);
    }
    len += 3 + size;
    gen->name = util_Calloc (len + 1, sizeof (char));
    L = strlen (mess);
    if (L > 0) {
        strncpy (gen->name, mess, len);
        if (mess[L - 1] != ':')
            strncat (gen->name, ":", 3);
        strncat (gen->name, "\n", 3);
    }
    strncat (gen->name, A->name, len);
    strncat (gen->name, "\n", 3);
    for (i=0; i<size; ++i) {
        strncat (gen->name, g[i]->name, len);
        strncat (gen->name, "\n", 3);
    }
    strncat (gen->name, name, len);

    gen->param  = NULL;
    gen->state  = paramC;
    gen->Write  = WrCombGenAPRNGFill;
    gen->GetU01 = GetU01CombGenAPRNGFill;
    gen->GetBits =GetBitsCombGenAPRNGFill;
    return gen;
}
Ejemplo n.º 17
0
unif01_Gen * unumrec_CreateRan2 (long s)
{
   unif01_Gen *gen;
   Ran0_param *param;
   Ran2_state *state;
   size_t leng;
   char name[LEN + 1];
   int i;
   long k;

   util_Assert (s > 0, "unumrec_CreateRan2:   s <= 0");
   gen = util_Malloc (sizeof (unif01_Gen));
   param = util_Malloc (sizeof (Ran0_param));
   state = util_Malloc (sizeof (Ran2_state));

   strncpy (name, "unumrec_CreateRan2:", LEN);
   addstr_Long (name, "   s = ", s);
   leng = strlen (name);
   gen->name = util_Calloc (leng + 1, sizeof (char));
   strncpy (gen->name, name, leng);

   param->Norm = 1.0 / M1;
   state->S1 = s;
   state->S2 = s;

   for (i = N_TAB8; i >= 1; i--) {
      k = state->S1 / q1;
      state->S1 = A1 * (state->S1 - k * q1) - k * r1;
      if (state->S1 < 0)
         state->S1 += M1;
      if (i <= N_TAB)
         state->Tab[i] = state->S1;
   }
   state->z = state->Tab[1];

   gen->GetBits = &Ran2_Bits;
   gen->GetU01  = &Ran2_U01;
   gen->Write   = &WrRan2;
   gen->param   = param;
   gen->state   = state;
   return gen;
}
Ejemplo n.º 18
0
sentrop_Res * sentrop_CreateRes (void)
{
   sentrop_Res *res;
   res = util_Malloc (sizeof (sentrop_Res));
   memset (res, 0, sizeof (sentrop_Res));
   res->Bas = sres_CreateBasic ();
   res->Count = util_Calloc (1, sizeof (long));
   res->jmax = 0;
   res->jmin = 0;
   return res;
}
Ejemplo n.º 19
0
fwalk_Res1 *fwalk_CreateRes1 (void)
{
    fwalk_Res1 *res;
    res = util_Malloc (sizeof (fwalk_Res1));
    res->H = fres_CreateCont ();
    res->M = fres_CreateCont ();
    res->J = fres_CreateCont ();
    res->R = fres_CreateCont ();
    res->C = fres_CreateCont ();
    return res;
}
Ejemplo n.º 20
0
unif01_Gen * uautomata_CreateCA90mp (int m, int S[])
{
   unif01_Gen *gen;
   CA90mp_state *state;
   size_t leng;
   char name[LEN + 1];
   int i;

   gen = util_Malloc (sizeof (unif01_Gen));
   state = util_Malloc (sizeof (CA90mp_state));

   strncpy (name, "uautomata_CreateCA90mp:", (size_t) LEN);
   addstr_Long (name, "   m = ", (long) m);
   addstr_ArrayInt (name, ",   S = ",  m, S);
   leng = strlen (name);
   gen->name = util_Calloc (leng + 1, sizeof (char));
   strncpy (gen->name, name, (size_t) leng);

   state->Cell = util_Calloc ((size_t) m + 2, sizeof (int));
   state->OldCell = util_Calloc ((size_t) m + 2, sizeof (int));
   state->m = m;

   for (i = 1; i <= m; i++) {
      util_Assert (S[i] == 0 || S[i] == 1,
        "uautomata_CreateCA90mp:   all S[i] must be in { 0, 1 }.");
      state->Cell[i] = S[i];
   }
   /* Null boundary condition */
   state->Cell[0] = 0;
   state->OldCell[0] = 0;
   gen->GetBits = &CA90mp_Bits;
   gen->GetU01  = &CA90mp_U01;
   gen->Write   = &WrCA90mp;
   gen->state   = state;
   gen->param   = NULL;
   return gen;
}
Ejemplo n.º 21
0
ffam_Fam * ffam_CreateFam (int Ng, char *name)
{
    ffam_Fam *fam;
    size_t len;

    fam = util_Malloc (sizeof (ffam_Fam));
    fam->Resol = util_Calloc ((size_t) Ng, sizeof (int));
    fam->LSize = util_Calloc ((size_t) Ng, sizeof (int));
    fam->Gen = util_Calloc ((size_t) Ng, sizeof (unif01_Gen *));
    fam->Ng = Ng;
    len = strlen (name);
    fam->name = util_Calloc (1 + len, sizeof (char));
    strncpy (fam->name, name, (size_t) len);
    return fam;
}
Ejemplo n.º 22
0
sres_Chi2 *sres_CreateChi2 (void)
{
   sres_Chi2 *res;
   res = (sres_Chi2 *)util_Malloc (sizeof (sres_Chi2));
   memset (res, 0, sizeof (sres_Chi2));
   res->sVal1 = statcoll_Create (1, "");
   res->pVal1 = statcoll_Create (1, "");
   res->name = (char*)util_Calloc (1, sizeof (char));
   res->jmin = 0;
   res->jmax = -1;
   res->NbExp = NULL;
   res->Count = NULL;
   res->Loc = NULL;
   return res;
}
Ejemplo n.º 23
0
static unif01_Gen *CreateWeyl_0 (double Alpha, long n0, char name[])
{
   unif01_Gen *gen;
   Weyl_param *param;
   Weyl_state *state;
   size_t leng;

   gen = util_Malloc (sizeof (unif01_Gen));
   param = util_Malloc (sizeof (Weyl_param));
   state = util_Malloc (sizeof (Weyl_state));
   param->Alpha = Alpha;
   state->n = n0;

   addstr_Double (name, "  Alpha = ", Alpha);
   addstr_Long (name, ",   n0 = ", n0);
   leng = strlen (name);
   gen->name = util_Calloc (leng + 1, sizeof (char));
   strncpy (gen->name, name, leng);

   gen->Write = &WrWeyl;
   gen->param = param;
   gen->state = state;
   return gen;
}
Ejemplo n.º 24
0
ftab_Table *ftab_CreateTable (int Nr, int j1, int j2, int jstep,
   char *Desc, ftab_FormType Form, int Ns)
{
   ftab_Table *T;
   T = util_Malloc (sizeof (ftab_Table));
   memset (T, 0, sizeof (ftab_Table));
   T->Nr = Nr;
   T->j1 = j1;
   T->j2 = j2;
   T->jstep = jstep;
   T->Nc = 1 + (j2 - j1)/jstep;
   T->Mat = tables_CreateMatrixD (T->Nr, T->Nc);
   T->LSize = util_Calloc ((size_t) T->Nr, sizeof (int));
   T->Desc = NULL;
   ftab_SetDesc (T, Desc);
   T->Form = Form;
   if (Form == ftab_String) {
      T->Strings = util_Calloc ((size_t) Ns, sizeof (char *));
      T->Ns = Ns;
   } else
      T->Strings = NULL;
   return T;
}
Ejemplo n.º 25
0
static unif01_Gen * CreateTaus_0 (char *na, unsigned int k, unsigned int q,
   unsigned int s, unsigned int Y)
{
   unif01_Gen *gen;
   Taus_param *param;
   Taus_state *state;
   size_t len;
   char name[LEN0 + 1];
   char str[LEN1 + 1];
   unsigned int B;

   strncpy (str, na, (size_t) LEN1);
   strncat (str, ":   Invalid Parameter", (size_t) LEN1 - 30);
   util_Assert ((k <= 32) && (k > 2 * q) && (s <= k - q) &&
                (s >= 1) && (q >= 1), str);
   /* These restrictions implies, for 32 bits int, */
   /* 0 < k <= 32 ; 0 < q < 16 ; 0 < s < 32 ; 0 < k - s < 32 */

   gen   = util_Malloc (sizeof (unif01_Gen));
   param = util_Malloc (sizeof (Taus_param));
   state = util_Malloc (sizeof (Taus_state));

   strncpy (name, na, (size_t) LEN0);
   addstr_Uint (name, ":   k = ", k);
   addstr_Uint (name, ",  q = ", q);
   addstr_Uint (name, ",  s = ", s);
   addstr_Uint (name, ",  Y = ", Y);
   len = strlen (name);
   gen->name = util_Calloc (len + 1, sizeof (char));
   strncpy (gen->name, name, len);

   param->Q1 = q;
   param->K1mS1 = k - s;
   param->S1 = s;

  /* k most signif. bits at 1 */
   B = num_TwoExp[32 - k] - 1.0;
   param->M1 = ~B;

   util_Assert (param->M1 > 0, "CreateTaus_0:   M1 = 0");

   strncpy (str, na, (size_t) LEN1);
   strncat (str, ":   Y = 0", (size_t) LEN1 - 30);
   util_Assert (Y > 0, str);
   state->ST1 = Y & param->M1;

   /* make sure that the initial state is not 0 */
   while (state->ST1 == 0) {
      Y *= 2;
      state->ST1 = Y & param->M1;
   }
   B = ((state->ST1 << param->Q1) ^ state->ST1) >> k;
   if (k >= 8 * sizeof (int))
      B = 0;                      /* B = B >> 32 does not work */
   state->ST1 ^= B;

   gen->GetBits = &Taus_Bits;
   gen->GetU01  = &Taus_U01;
   gen->Write   = &WrTaus;
   gen->param   = param;
   gen->state   = state;
   return gen;
}
Ejemplo n.º 26
0
unif01_Gen * utaus_CreateCombTaus3 (unsigned int k1, unsigned int k2,
   unsigned int k3, unsigned int q1, unsigned int q2, unsigned int q3,
   unsigned int s1, unsigned int s2, unsigned int s3, unsigned int Y1,
   unsigned int Y2, unsigned int Y3)
{
   unif01_Gen *gen;
   CombTaus3_param *param;
   CombTaus3_state *state;
   size_t len;
   char name[LEN0 + 1];
   unsigned int B;

   util_Assert (
      (k1 <= 32) && (k1 > 2 * q1) && (s1 <= k1 - q1) && (s1 > 0) &&
      (k2 <= 32) && (k2 > 2 * q2) && (s2 <= k2 - q2) && (s2 > 0) &&
      (k3 <= 32) && (k3 > 2 * q3) && (s3 <= k3 - q3) && (s3 > 0) &&
      (q1 > 0) && (q2 > 0) && (q3 > 0) && (k1 >= k2) && (k2 >= k3),
      "utaus_CreateCombTaus3:   Invalid Parameter");

   strncpy (name, "utaus_CreateCombTaus3:", (size_t) LEN0);
   addstr_Uint (name, "   (k1, k2, k3) = ", k1);
   addstr_Uint (name, ", ", k2);
   addstr_Uint (name, ", ", k3);
   addstr_Uint (name, ",   (q1, q2, q3) = ", q1);
   addstr_Uint (name, ", ", q2);
   addstr_Uint (name, ", ", q3);
   addstr_Uint (name, ",   (s1, s2, s3) = ", s1);
   addstr_Uint (name, ", ", s2);
   addstr_Uint (name, ", ", s3);
   addstr_Uint (name, ",   (Y1, Y2, Y3) = ", Y1);
   addstr_Uint (name, ", ", Y2);
   addstr_Uint (name, ", ", Y3);

   gen = util_Malloc (sizeof (unif01_Gen));
   param = gen->param = util_Malloc (sizeof (CombTaus3_param));
   state = gen->state = util_Malloc (sizeof (CombTaus3_state));
   gen->GetU01  = &CombTaus3_U01;
   gen->GetBits = &CombTaus3_Bits;
   gen->Write   = &WrCombTaus3;

   len = strlen (name);
   gen->name = util_Calloc (len + 1, sizeof (char));
   strncpy (gen->name, name, len);

   param->Q1 = q1;
   param->S1 = s1;
   param->K1mS1 = k1 - s1;
   param->M1 = num_TwoExp[32 - k1] - 1; /* k1 most sig. bits at 1 */
   param->M1 = ~param->M1;

   param->Q2 = q2;
   param->S2 = s2;
   param->K2mS2 = k2 - s2;
   param->M2 = num_TwoExp[32 - k2] - 1; /* k2 most sig. bits at 1 */
   param->M2 = ~param->M2;

   param->Q3 = q3;
   param->S3 = s3;
   param->K3mS3 = k3 - s3;
   param->M3 = num_TwoExp[32 - k3] - 1; /* k3 most sig. bits at 1 */
   param->M3 = ~param->M3;

   /* Initialisation as in L'Ecuyer 1996. */
   util_Assert (Y1 > 0, "utaus_CreateCombTaus3:   seed1 = 0");
   state->ST1 = Y1 & param->M1;
   while (state->ST1 == 0) {      /* Make sure the initial state is not 0 */
      Y1 = Y1 * 2;
      state->ST1 = Y1 & param->M1;
   }
   B = ((state->ST1 << param->Q1) ^ state->ST1) >> k1;
   if (k1 >= 8 * sizeof (int))
      B = 0;                      /* B = B >> 32 does not work */
   state->ST1 = state->ST1 ^ B;

   util_Assert (Y2 > 0, "utaus_CreateCombTaus3:   seed2 = 0");
   state->ST2 = Y2 & param->M2;
   while (state->ST2 == 0) {      /* Make sure the initial state is not 0 */
      Y2 = Y2 * 2;
      state->ST2 = Y2 & param->M2;
   }
   B = ((state->ST2 << param->Q2) ^ state->ST2) >> k2;
   if (k2 >= 8 * sizeof (int))
      B = 0;                      /* B = B >> 32 does not work */
   state->ST2 = state->ST2 ^ B;

   util_Assert (Y3 > 0, "utaus_CreateCombTaus3:   seed3 = 0");
   state->ST3 = Y3 & param->M3;
   while (state->ST3 == 0) {      /* Make sure the initial state is not 0 */
      Y3 = Y3 * 2;
      state->ST3 = Y3 & param->M3;
   }
   B = ((state->ST3 << param->Q3) ^ state->ST3) >> k3;
   if (k3 >= 8 * sizeof (int))
      B = 0;                      /* B = B >> 32 does not work */
   state->ST3 = state->ST3 ^ B;

   return gen;
}
Ejemplo n.º 27
0
unif01_Gen * uautomata_CreateCA1 (int N, int S[ ], int r, int F[ ], 
                                  int k, int ts, int cs, int rot)
{
   unif01_Gen *gen;
   CA1_param *param;
   CA1_state *state;
   size_t leng;
   char name[LEN + 1];
   long i;
   unsigned long Z = 0;
   long L;                 /* Dimension of the rule F */

   i = 4*sizeof(long) - 1;
   util_Assert ((long) r < i, "uautomata_CreateCA1:   r too large");
   util_Assert (ts >= 0, "uautomata_CreateCA1:   ts < 0");
   util_Assert (cs >= 0, "uautomata_CreateCA1:   cs < 0");
   util_Assert (k > 0,  "uautomata_CreateCA1:   k < 1");
   gen = util_Malloc (sizeof (unif01_Gen));
   param = util_Malloc (sizeof (CA1_param));
   state = util_Malloc (sizeof (CA1_state));

   strncpy (name, "uautomata_CreateCA1:", (size_t) LEN);
   addstr_Long (name, "   N = ", (long) N);
   addstr_Long (name, ",   r = ", (long) r);
   L = num_TwoExp[2*r + 1];
   addstr_ArrayInt (name, ",   F = ",  (int) L, F);
   for (i = L-1; i >= 0; i--) {
      Z <<= 1;
      Z += F[i];
   }
   addstr_Ulong(name, " = Rule ", Z);   
   addstr_Long (name, ",   k = ", (long) k);
   addstr_Long (name, ",   ts = ", (long) ts);
   addstr_Long (name, ",   cs = ", (long) cs);
   addstr_Long (name, ",   rot = ", (long) rot);
   addstr_ArrayInt (name, ",   S = ",  N, S);
   leng = strlen (name);
   gen->name = util_Calloc (leng + 1, sizeof (char));
   strncpy (gen->name, name, (size_t) leng);

   param->r = r;
   param->tstep = ts + 1;
   param->cstep = cs + 1;
   param->rot = rot;
   param->k = k;
   param->F = F;
   param->L = L;
   state->Cell = util_Calloc ((size_t) N, sizeof (int));
   state->OldCell = util_Calloc ((size_t) N, sizeof (int));
   state->Rand = util_Calloc ((size_t) k, sizeof (unsigned long));
   state->N = N;
   state->nk = 0;
   param->imin = N/2 - k/2 * param->cstep;
   param->imax = N/2 + (k - 1)/2 * param->cstep;
   util_Assert (param->imin >= 0, "uautomata_CreateCA1:   k*cs too large");
   util_Assert (param->imax < N, "uautomata_CreateCA1:   k*cs too large");

   for (i = 0; i < N; i++) {
     /*     util_Assert (S[i] == 0 || S[i] == 1,
            "uautomata_CreateCA1:   all S[i] must be in { 0, 1 }."); */
      state->Cell[i] = S[i] & 1;
   }
   
   gen->GetBits = &CA1_Bits;
   gen->GetU01  = &CA1_U01;
   gen->Write   = &WrCA1;
   gen->param   = param;
   gen->state   = state;
   return gen;
}