Tscope5
randomizer.c
Go to the documentation of this file.
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 #include "../include/tscope5/randomizer.h"
11 #include "../include/tscope5/randomizer_internal.h"
12 #include "../include/tscope5/system_internal.h"
13 
14 #include <gsl/gsl_rng.h>
15 #include <gsl/gsl_randist.h>
16 #include <sys/time.h>
17 
18 
23 
24 
25 
26 
34 unsigned long int ts5_random_integer(const unsigned int max)
35 {
36  ts5_check_randomizer("ts5_random_integer");
37  ts5_log(TS5_LOGLEVEL_5, "ts5_random_integer(%u)\n", max);
38 
39  return gsl_rng_uniform_int(_ts5_status.randomizer, (long)max);
40 }
41 
42 
50 void ts5_random_list(const int nmax, const int freq, int *list)
51 {
52  ts5_check_randomizer("ts5_random_list");
53  ts5_log(TS5_LOGLEVEL_5, "ts5_random_list(%d,%d,%p)\n", nmax, freq, list);
54 
55  int i;
56  for (i = 0; i < nmax * freq; i++) {
57  list[i] = i % nmax;
58  }
59 
60  gsl_ran_shuffle(_ts5_status.randomizer, list, (unsigned long)(nmax * freq), sizeof(int));
61 }
62 
64 
65 
66 
67 
71 
72 
73 
74 
83 {
84  ts5_check_randomizer("ts5_random_uniform");
85  ts5_log(TS5_LOGLEVEL_5, "ts5_random_uniform()\n");
86 
87  return gsl_rng_uniform(_ts5_status.randomizer);
88 }
89 
90 
99 double ts5_random_normal(double mu, double sigma)
100 {
101  ts5_check_randomizer("ts5_random_normal");
102  ts5_log(TS5_LOGLEVEL_5, "ts5_random_normal(%f,%f)\n", mu, sigma);
103 
104  return (mu + gsl_ran_gaussian(_ts5_status.randomizer, sigma));
105 }
106 
107 
115 double ts5_random_exponential(double mu)
116 {
117  ts5_check_randomizer("ts5_random_exponential");
118  ts5_log(TS5_LOGLEVEL_5, "ts5_random_exponential(%f)\n", mu);
119 
120  return gsl_ran_exponential(_ts5_status.randomizer, mu);
121 }
122 
123 
128 
129 
130 
131 
142 unsigned long int ts5_seed_randomizer(const unsigned int seed)
143 {
144  ts5_check_randomizer("ts5_seed_randomizer");
145  ts5_log(TS5_LOGLEVEL_4, "ts5_seed_randomizer(%u)\n", seed);
146 
147  gsl_rng_set(_ts5_status.randomizer, (long)seed);
148 
149  return seed;
150 }
151 
152 
154 
155