Version: 8.3.0
aleas.cxx File Reference
#include <time.h>
#include <sys/types.h>
#include <unistd.h>
#include <math.h>
#include "aleas.hxx"
Include dependency graph for aleas.cxx:

Go to the source code of this file.

Macros

#define NOALEAS
 

Functions

void init_by_array (unsigned long[], int)
 
double genrand_real1 (void)
 
double genrand_real3 (void)
 
static void initrand (void)
 
static double randGauss (void)
 

Macro Definition Documentation

#define NOALEAS

Definition at line 35 of file aleas.cxx.

Function Documentation

double genrand_real1 ( void  )

Definition at line 122 of file mt19937ar.cxx.

References genrand_int32().

Referenced by Sphere::fill(), and Cube::tire().

123 {
124  return genrand_int32()*(1.0/4294967295.0);
125  /* divided by 2^32-1 */
126 }
double genrand_real3 ( void  )

Definition at line 136 of file mt19937ar.cxx.

References genrand_int32().

Referenced by randGauss().

137 {
138  return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0);
139  /* divided by 2^32 */
140 }
void init_by_array ( unsigned  long[],
int   
)

Definition at line 52 of file mt19937ar.cxx.

References CORBAEngineTest::i, init_genrand(), mt, and N.

Referenced by initrand().

53 {
54  int i, j, k;
55  init_genrand(19650218UL);
56  i=1; j=0;
57  k = (N>key_length ? N : key_length);
58  for (; k; k--) {
59  mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
60  + init_key[j] + j; /* non linear */
61  mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
62  i++; j++;
63  if (i>=N) { mt[0] = mt[N-1]; i=1; }
64  if (j>=key_length) j=0;
65  }
66  for (k=N-1; k; k--) {
67  mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
68  - i; /* non linear */
69  mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
70  i++;
71  if (i>=N) { mt[0] = mt[N-1]; i=1; }
72  }
73 
74  mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
75 }
static void initrand ( void  )
static

Definition at line 37 of file aleas.cxx.

References init_by_array().

Referenced by Aleatoire::Aleatoire().

38 {
39  static long done=0;
40  unsigned long vec[]={
41  31081996, 21012006, 17921963, 0,
42  11101998, 2112003, 25111964, 0
43  };
44 
45  if (! done) {
46 #ifdef NOALEAS
47  vec[3] = vec[7] = 2082007;
48 #else
49  vec[3] = (unsigned long) getpid();
50  vec[7] = (unsigned long) time(NULL);
51 #endif
52  init_by_array(vec, 8);
53  done += 1;
54  }
55 }
static double randGauss ( void  )
static

Definition at line 73 of file aleas.cxx.

References genrand_real3(), and gui.logview::log.

Referenced by Normale::tire(), and NormalePositif::tire().

74 {
75  static double next;
76  static int flag=0;
77  double v2, d, fac;
78 
79  if (flag) {
80  flag = 0;
81  return next;
82  }
83  else {
84  do {
85  next = 2.0*genrand_real3() - 1.0;
86  v2 = 2.0*genrand_real3() - 1.0;
87  d = next*next + v2*v2;
88  } while (d >= 1.0 || d == 0.0);
89  fac = sqrt(-2.0*log(d)/d);
90  next *= fac;
91  flag = 1;
92  return v2 * fac;
93  }
94 
95 }