56 static vector<unsigned long int> seeds;
58 #pragma omp critical(Rng_seed) 60 unsigned long int n_orig =
n;
62 while (find(seeds.begin(), seeds.end(),
n) != seeds.end()) {
63 if (n >= ULONG_MAX - 1)
73 <<
"Rng Warning: Couldn't find an unused seed. Clearing seed pool.\n";
160 static inline unsigned long int mt_get(
void *vstate);
161 static double mt_get_double(
void *vstate);
162 static void mt_set(
void *state,
unsigned long int s);
168 static const unsigned long UPPER_MASK = 0x80000000UL;
171 static const unsigned long LOWER_MASK = 0x7fffffffUL;
178 static inline unsigned long mt_get(
void *vstate) {
182 unsigned long int *
const mt = state->
mt;
184 #define MAGIC(y) (((y)&0x1) ? 0x9908b0dfUL : 0) 186 if (state->
mti >=
N) {
189 for (kk = 0; kk <
N -
M; kk++) {
190 unsigned long y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
191 mt[kk] = mt[kk +
M] ^ (y >> 1) ^
MAGIC(y);
193 for (; kk <
N - 1; kk++) {
194 unsigned long y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
195 mt[kk] = mt[kk + (M -
N)] ^ (y >> 1) ^
MAGIC(y);
199 unsigned long y = (mt[N - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
200 mt[N - 1] = mt[M - 1] ^ (y >> 1) ^
MAGIC(y);
210 k ^= (k << 7) & 0x9d2c5680UL;
211 k ^= (k << 15) & 0xefc60000UL;
219 static double mt_get_double(
void *vstate) {
220 return (
double)mt_get(vstate) / 4294967296.0;
223 static void mt_set(
void *vstate,
unsigned long int s) {
227 if (s == 0) s = 4357;
229 state->
mt[0] = s & 0xffffffffUL;
231 for (i = 1; i <
N; i++) {
236 (1812433253UL * (state->
mt[i - 1] ^ (state->
mt[i - 1] >> 30)) +
i);
238 state->
mt[
i] &= 0xffffffffUL;
279 if (i == N1) abort(); \ 280 gsl_rng_generator_types[i] = (t); \ 287 ADD(gsl_rng_mt19937);
318 const char *reason) {
323 (*gsl_stream_handler)(label, file, line, reason);
326 fprintf(
gsl_stream,
"gsl: %s:%d: %s: %s\n", file, line, label, reason);
333 return previous_handler;
337 FILE *previous_stream;
343 return previous_stream;
367 static void no_error_handler(
const char *reason,
372 void gsl_error(
const char *reason,
const char *file,
int line,
int gsl_errno) {
374 (*gsl_error_handler)(reason, file, line, gsl_errno);
380 fprintf(stderr,
"Default GSL error handler invoked.\n");
387 return previous_handler;
393 return previous_handler;
396 static void no_error_handler(
const char *reason
_U_,
397 const char *file
_U_,
481 #ifndef HIDE_INLINE_STATIC 500 unsigned long int offset = r->
type->
min;
501 unsigned long int range = r->
type->
max - offset;
502 unsigned long int scale = range /
n;
529 unsigned char *p = (
unsigned char *)(r->
state);
532 for (i = 0; i <
n; i++) {
534 printf(
"%.2x", *(p + i));
void gsl_stream_printf(const char *label, const char *file, int line, const char *reason)
const gsl_rng_type * type
Declarations having to do with the four output streams.
gsl_rng * gsl_rng_clone(const gsl_rng *q)
unsigned long int gsl_rng_max(const gsl_rng *r)
void force_seed(unsigned long int n)
Seeds the Rng with the integer argument.
FILE * gsl_set_stream(FILE *new_stream)
void gsl_rng_print_state(const gsl_rng *r)
gsl_rng * gsl_rng_alloc(const gsl_rng_type *T)
void gsl_error_handler_t(const char *reason, const char *file, int line, int gsl_errno)
Rng()
Constructor creates instance of gsl_rng of type gsl_rng_mt19937.
void gsl_rng_set(const gsl_rng *r, unsigned long int seed)
~Rng()
Destructor frees memory allocated to gsl_rng.
const gsl_rng_type * gsl_rng_mt19937
#define GSL_ERROR_VAL(reason, gsl_errno, value)
unsigned long int gsl_rng_uniform_int(const gsl_rng *r, unsigned long int n)
The global header file for ARTS.
void gsl_stream_handler_t(const char *label, const char *file, int line, const char *reason)
void(* set)(void *state, unsigned long int seed)
unsigned long int(* get)(void *state)
gsl_error_handler_t * gsl_error_handler
member functions of the Rng class and gsl_rng code
void gsl_error(const char *reason, const char *file, int line, int gsl_errno)
gsl_stream_handler_t * gsl_stream_handler
void * gsl_rng_state(const gsl_rng *r)
unsigned long int showseed() const
Returns the seed number.
unsigned long int gsl_rng_get(const gsl_rng *r)
unsigned long int gsl_rng_default_seed
double draw()
Draws a double from the uniform distribution [0,1)
int gsl_rng_memcpy(gsl_rng *dest, const gsl_rng *src)
#define GSL_ERROR(reason, gsl_errno)
gsl_stream_handler_t * gsl_set_stream_handler(gsl_stream_handler_t *new_handler)
double(* get_double)(void *state)
size_t gsl_rng_size(const gsl_rng *r)
const gsl_rng_type ** gsl_rng_types_setup(void)
const char * gsl_rng_name(const gsl_rng *r)
unsigned long int gsl_rng_min(const gsl_rng *r)
double gsl_rng_uniform(const gsl_rng *r)
void seed(unsigned long int n, const Verbosity &verbosity)
Seeds the Rng with the integer argument.
gsl_error_handler_t * gsl_set_error_handler(gsl_error_handler_t *new_handler)
void gsl_rng_free(gsl_rng *r)
unsigned long int seed_no
const gsl_rng_type * gsl_rng_generator_types[N1]
double gsl_rng_uniform_pos(const gsl_rng *r)
gsl_error_handler_t * gsl_set_error_handler_off(void)