Example #1
0
/**
		This function initializes all global generators by @a seed value.

@param seed The seed value of all generators.
*/
void srand(RandomValue seed)
{
	OMNI_MT_CODE(sync::AutoLock guard(g_lock()));

	g_rand() = Random(seed);
	g_unif() = Uniform(seed);
	g_norm() = Normal(seed);
	g_exp() = Exponential(seed);

	g_seed() = seed;
}
Example #2
0
File: sort.c Project: z88dk/z88dk
int main(void)
{
#ifdef __Z88DK
   intrinsic_di();
#endif

   PRINTF1("\nFilling the array with numbers.\n\n");
   
   /* FILL ARRAY WITH NUMBERS */
   
   for (i = 0; i < NUM; ++i)
#if STYLE == 0
      numbers[i] = g_rand();
#else
#if STYLE == 1
      numbers[i] = i;
#else
#if STYLE == 2
      numbers[i] = NUM - i - 1;
#else
      numbers[i] = NUM/2;
#endif
#endif
#endif

   /* PRINT FIRST FEW NUMBERS TO DEMONSTRATE ALL IS GOOD */
   
   for (i = 0; i < 10; ++i)
      PRINTF2("%u, ", numbers[i]);
   
   /* SORT */
   
   PRINTF1("\n\nQSORT!!\n\n");
   perform_sort();

   /* VERIFY RESULT */
   
   for (i = 0; i < NUM; ++i)
   {
      PRINTF2("%u, ", numbers[i]);
      if ((i > 0) && (numbers[i] < numbers[i-1]))
      {
         PRINTF1("\n\nFAIL");
         break;
      }
   }
   
   PRINTF1("\n\n\n");
   
   return 0;
}
Example #3
0
/* ---------------- st_g_rand ---------------------------------
 * g_rand() gives us a floating point. This is to return items
 * of type size_t. If our mean is outside the range, return 0 and
 * hope the caller is clever enough to notice we are upset.
 */
size_t
st_g_rand (size_t mean, size_t std_dev)
{
    float x;
    size_t r;
    if (mean >= SSIZE_MAX)
        return 0;

    x = SSIZE_MAX + 1.0;
    do { 
        x = g_rand (mean, std_dev);
        r = (size_t) rint (x);
    } while ( x >= SSIZE_MAX);
    return r;
}
/* ---------------- score_rand  -------------------------------
 * Score two sequences using a gaussian distributed random numbers.
 */
void
score_rand (struct score_mat *score_mat, const float mean, const float std_dev)
{
    const size_t n_rows = score_mat->n_rows;
    const size_t n_cols = score_mat->n_cols;
    float **scores = score_mat->mat;
    size_t i, j;

    /* matrix is n_rows (s1), n_cols (s2) */
    for (i = 0; i < n_cols ; i++)
        scores[0][i] = 0;                   /* First row */
    for (i = 0; i < n_cols ; i++)
        scores[n_rows - 1][i] = 0;          /* Last row */
    for (i = 0; i < n_rows ; i++)
        scores [i][0] = 0;                  /* First column */
    for (i = 0; i < n_rows ; i++)
        scores [i][n_cols - 1 ] = 0;        /* Last column */

    for (i = 1; i < n_rows - 1; i++) {
        for (j = 1; j < n_cols - 1 ; j++) {
            scores [i][j] = g_rand (mean, std_dev);
        }
    }
}
Example #5
0
/**
		This function returns the maximum possible random value.

@return The maximum possible random value.
*/
RandomValue rand_max()
{
	return g_rand().rand_max();
}
Example #6
0
/**
		This function generates the random number in range [0, rand_max()].

@return The random number.
*/
RandomValue rand()
{
	OMNI_MT_CODE(sync::AutoLock guard(g_lock()));
	return g_rand()();
}