-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
39 lines (27 loc) · 645 Bytes
/
test.c
File metadata and controls
39 lines (27 loc) · 645 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
#include <stddef.h>
#include <stdio.h>
#include <math.h>
#include "crandom.h"
#define T (10000000)
#define N (1000)
#define A (-5)
#define B (5)
size_t histogram[N + 1];
int main() {
size_t i = 0;
struct cRandom * crandom = dSFMTRandomNew();
for(i = 0; i < T; ++i) {
double x = normal(crandom, 0, 1);
if( x < A )
x = A;
if( B < x )
x = B;
histogram[ (size_t) floor(N * (x - A) / (B - A)) ]++;
}
crandom->release(crandom);
for(i = 0; i <= N; ++i) {
if( histogram[i] )
printf("%.3f %.3f\n", A + ((double)i) * (B - A) / N, ((double)histogram[i]) * N / (T * (B - A)));
}
return 0;
}