forked from MersenneTwister-Lab/SFMT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample4.c
More file actions
34 lines (32 loc) · 682 Bytes
/
Copy pathsample4.c
File metadata and controls
34 lines (32 loc) · 682 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
#include <stdio.h>
#include <string.h>
#include "SFMT.h"
int main(int argc, char* argv[]) {
int i, cnt, seed_cnt;
double x, y, pi;
const int NUM = 10000;
uint32_t seeds[100];
sfmt_t sfmt;
if (argc >= 2) {
seed_cnt = 0;
for (i = 0; (i < 100) && (i < strlen(argv[1])); i++) {
seeds[i] = argv[1][i];
seed_cnt++;
}
} else {
seeds[0] = 12345;
seed_cnt = 1;
}
cnt = 0;
sfmt_init_by_array(&sfmt, seeds, seed_cnt);
for (i = 0; i < NUM; i++) {
x = sfmt_genrand_res53(&sfmt);
y = sfmt_genrand_res53(&sfmt);
if (x * x + y * y < 1.0) {
cnt++;
}
}
pi = (double)cnt / NUM * 4;
printf("%lf\n", pi);
return 0;
}