Random Generator
Betöltés...
Keresés...
Nincs egyezés
main.cpp
Ugrás a fájl dokumentációjához.
1
#include "
uniform.h
"
2
#include <iostream>
3
#include <fstream>
4
#include <vector>
5
#include <chrono>
6
#include <thread>
7
using namespace
std;
8
10
const
int
N_OF_SAMPLES
= 5;
12
const
int
N_OF_EXPERIMENTS
= 1000;
14
const
int
N_OF_RANDVALS
= 10;
15
17
21
int
main
() {
22
const
char
* output_file_name =
"uniform_test.csv"
;
23
ofstream output_file(output_file_name, ios::app);
24
if
(output_file.fail()) {
25
cerr <<
"Unable to open the file "
<< output_file_name
26
<<
" for writing."
<< endl;
27
return
1;
28
}
29
for
(
int
i = 0; i <
N_OF_SAMPLES
; ++i) {
30
bme::seed
();
31
vector<int> boxes(
N_OF_RANDVALS
,0);
32
for
(
int
j = 0; j <
N_OF_EXPERIMENTS
; j++) {
33
int
idx =
bme::unif
(
N_OF_RANDVALS
) - 1;
34
boxes[idx]++;
35
}
36
output_file <<
"GYAKORISAG,"
;
37
for
(
int
k = 0; k <
N_OF_RANDVALS
; k++) {
38
output_file << boxes[k] <<
","
;
39
}
40
output_file << endl;
41
output_file <<
"RELATIV GYAKORISAG,"
;
42
for
(
int
k = 0; k <
N_OF_RANDVALS
; k++) {
43
output_file << static_cast<double>(boxes[k])/
static_cast<
double
>
(
N_OF_EXPERIMENTS
) <<
","
;
44
}
45
output_file << endl;
46
using namespace
std::this_thread;
// sleep_for, sleep_until
47
using namespace
std::chrono;
// nanoseconds, system_clock, seconds
48
cout <<
"Waiting for 2 seconds"
<< endl;
49
sleep_for(seconds(2));
50
}
51
return
0;
52
}
N_OF_EXPERIMENTS
const int N_OF_EXPERIMENTS
egy mintánál a generált értékek száma
Definition
main.cpp:12
N_OF_SAMPLES
const int N_OF_SAMPLES
a generált minták száma
Definition
main.cpp:10
main
int main()
main függvény a véletlenszám-generátor tesztelésére
Definition
main.cpp:21
N_OF_RANDVALS
const int N_OF_RANDVALS
a különböző lehetőségek száma a generált értékre
Definition
main.cpp:14
bme::seed
void seed()
Véletlenszám-generátort inicializálása.
Definition
uniform.cpp:23
bme::unif
double unif()
Egyenletes eloszlás a (0,1) intervallumon.
Definition
uniform.cpp:9
uniform.h
Véletlenszám-generátor.
main.cpp
Készítette
1.13.2