Go to the documentation of this file.
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); \
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_,
462 r->
state = malloc(
q->type->size);
472 memcpy(r->
state,
q->state,
q->type->size);
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_rng_print_state(const gsl_rng *r)
unsigned long int gsl_rng_max(const gsl_rng *r)
unsigned long int gsl_rng_min(const gsl_rng *r)
unsigned long int showseed() const
Returns the seed number.
gsl_stream_handler_t * gsl_set_stream_handler(gsl_stream_handler_t *new_handler)
~Rng()
Destructor frees memory allocated to gsl_rng.
unsigned long int seed_no
FILE * gsl_set_stream(FILE *new_stream)
const gsl_rng_type * type
const gsl_rng_type ** gsl_rng_types_setup(void)
Verbosity verbosity(Workspace &ws) noexcept
const gsl_rng_type * gsl_rng_mt19937
void seed(unsigned long int n, const Verbosity &verbosity)
Seeds the Rng with the integer argument.
unsigned long int(* get)(void *state)
Vector y(Workspace &ws) noexcept
gsl_error_handler_t * gsl_set_error_handler(gsl_error_handler_t *new_handler)
double gsl_rng_uniform_pos(const gsl_rng *r)
gsl_error_handler_t * gsl_set_error_handler_off(void)
unsigned long int gsl_rng_get(const gsl_rng *r)
unsigned long int gsl_rng_default_seed
double(* get_double)(void *state)
gsl_rng * gsl_rng_clone(const gsl_rng *q)
member functions of the Rng class and gsl_rng code
double draw()
Draws a double from the uniform distribution [0,1)
void force_seed(unsigned long int n)
Seeds the Rng with the integer argument.
gsl_stream_handler_t * gsl_stream_handler
void gsl_stream_handler_t(const char *label, const char *file, int line, const char *reason)
Declarations having to do with the four output streams.
gsl_error_handler_t * gsl_error_handler
void gsl_error_handler_t(const char *reason, const char *file, int line, int gsl_errno)
#define GSL_ERROR_VAL(reason, gsl_errno, value)
void * gsl_rng_state(const gsl_rng *r)
#define GSL_ERROR(reason, gsl_errno)
void(* set)(void *state, unsigned long int seed)
gsl_rng * gsl_rng_alloc(const gsl_rng_type *T)
unsigned long int gsl_rng_uniform_int(const gsl_rng *r, unsigned long int n)
Rng()
Constructor creates instance of gsl_rng of type gsl_rng_mt19937.
size_t gsl_rng_size(const gsl_rng *r)
void gsl_error(const char *reason, const char *file, int line, int gsl_errno)
const gsl_rng_type * gsl_rng_generator_types[N1]
const char * gsl_rng_name(const gsl_rng *r)
void gsl_rng_free(gsl_rng *r)
void gsl_stream_printf(const char *label, const char *file, int line, const char *reason)
Vector x(Workspace &ws) noexcept
double gsl_rng_uniform(const gsl_rng *r)
The global header file for ARTS.
void gsl_rng_set(const gsl_rng *r, unsigned long int seed)
int gsl_rng_memcpy(gsl_rng *dest, const gsl_rng *src)