aboutsummaryrefslogtreecommitdiff
path: root/random.h
blob: 8603ba8d14fd1852e8ee429f724ecae6ed1f9bbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/****************************************************************
*****************************************************************
    _/    _/  _/_/_/  _/       Numerical Simulation Laboratory
   _/_/  _/ _/       _/       Physics Department
  _/  _/_/    _/    _/       Universita' degli Studi di Milano
 _/    _/       _/ _/       Prof. D.E. Galli
_/    _/  _/_/_/  _/_/_/_/ email: Davide.Galli@unimi.it
*****************************************************************
*****************************************************************/

#ifndef __Random__
#define __Random__

#define M_PI 3.14159265358979323846 /* pi */

// State for the RANNYU random numbers generator
typedef struct Random Random;
struct Random {
	int m1, m2, m3, m4, l1, l2, l3, l4, n1, n2, n3, n4;
};

// Initialize Random from open file pointers
bool random_init(Random rnd[static 1], FILE *primes, FILE *input);
// Method to set the seed for the RNG
void random_set_seed(Random rnd[static 1], int[4], int, int);
// Method to save the seed to a bool
bool random_save_seed(
        const Random rnd[static 1], const char filename[static 1]);
// Method to generate a random number in the range [0,1)
double random_rannyu(Random rnd[static 1]);
// Method to generate a random number in the range [min,max)
double random_rannyu_range(Random rnd[static 1], double min, double max);
// Method to generate a random number with a Gaussian distribution
double random_gauss(Random rnd[static 1], double mean, double sigma);
// Method to generate a random number with an Exponential distribution
double random_exp(Random rnd[static 1], double lambda);
// Method to generate a random number with a Cauchy-Lorentz
// distribution
double random_lorentz(Random rnd[static 1], double mean, double gamma);

#endif // __Random__

/****************************************************************
*****************************************************************
    _/    _/  _/_/_/  _/       Numerical Simulation Laboratory
   _/_/  _/ _/       _/       Physics Department
  _/  _/_/    _/    _/       Universita' degli Studi di Milano
 _/    _/       _/ _/       Prof. D.E. Galli
_/    _/  _/_/_/  _/_/_/_/ email: Davide.Galli@unimi.it
*****************************************************************
*****************************************************************/