コード例 #1
0
ファイル: random.c プロジェクト: Koliham/COPASI
double rnormal01(void)
{
  static char f = 1;
  static double y;
  double a, b, s;
  double mean = 0;
  double sd = 1;

  /* negate the flag */
  f = -f;
  /* return the stored number (if one is there) */
  if (f > 0) return y;
  for (;;)
    {
      a = 2.0 * dr250() - 1.0;
      b = 2.0 * dr250() - 1.0;
      s = a * a + b * b;
      if ((s < 1.0) && (s != 0)) break;
    }
  s = sqrt(-2.0 * log(s) / s);
  // save one of the numbers for the next time
  y = sd * s * a + mean;
  // and return the other
  return sd * s*b + mean;
}
コード例 #2
0
ファイル: nps_random.c プロジェクト: BrandoJS/paparazzi
/*
   http://www.taygeta.com/random/gaussian.html
*/
double get_gaussian_noise(void) {

  double x1;
  static int nb_call = 0;
  static double x2, w;
  if (nb_call==0) r250_init(0);
  nb_call++;
  if (nb_call%2) {
    do {
      x1 = 2.0 * dr250() - 1.0;
      x2 = 2.0 * dr250() - 1.0;
      w = x1 * x1 + x2 * x2;
    } while ( w >= 1.0 );

    w = sqrt( (-2.0 * log( w ) ) / w );
    return x1 * w;
  }
  else
    return x2 * w;
}
コード例 #3
0
ファイル: random250.cpp プロジェクト: biodynamical/euneurone
/*---------------------------------------------------------------------------*/
double rnd(void)
{
  return dr250();
}