-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrnd.c
More file actions
43 lines (34 loc) · 765 Bytes
/
rnd.c
File metadata and controls
43 lines (34 loc) · 765 Bytes
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
/*rnd.c*/
#include <math.h>
#include <stdlib.h>
#include <time.h>
/*#define NULL 0*/
#define FRAC(y) modf((y), &no)
double rnd();
double gaussn();
static double no = 3.0;
static double a = 9821.0, c = 0.211327, x = 0.0;
double rnd() {
x = FRAC(a * x + c);
return x;
}
void rndseed() {
srand ( time(0) );
int r = rand();
x = (double)(r%10000)/10000;
}
static double m = 0.0, sigma = 1.0, K = 20, s12dk = 0.7746;
void gausset(double mm, double ss) {
m = mm;
s12dk = sqrt(12 / K);
sigma = ss;
s12dk = sqrt(12 / K);
}
double gaussn() {
double S = 0.0;
static int i;
for (i = 0; i < K; i++)
S += rnd();
return s12dk * (S - K / 2.0);
}
double rndgauss() { return sigma * gaussn() + m; }