Example #1
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;
}
Example #2
0
void  addstr_ArrayLong (char *to, const char *add, int high, long val[])
{
   int j;
   strcat (to, add);
   addstr_Long (to, "(", val[0]);
   for (j = 1; (j < high) && (j < 5); j++)
      addstr_Long (to, ", ", val[j]);
   if (high > 5)
      strcat (to, ", ... )");
   else
      strcat (to, ")");
}
Example #3
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;
}
Example #4
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;
}
Example #5
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;
}
Example #6
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;
}
Example #7
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;
}