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>
7using namespace std;
8
10const int N_OF_SAMPLES = 5;
12const int N_OF_EXPERIMENTS = 1000;
14const int N_OF_RANDVALS = 10;
15
17
21int 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}
const int N_OF_EXPERIMENTS
egy mintánál a generált értékek száma
Definition main.cpp:12
const int N_OF_SAMPLES
a generált minták száma
Definition main.cpp:10
int main()
main függvény a véletlenszám-generátor tesztelésére
Definition main.cpp:21
const int N_OF_RANDVALS
a különböző lehetőségek száma a generált értékre
Definition main.cpp:14
void seed()
Véletlenszám-generátort inicializálása.
Definition uniform.cpp:23
double unif()
Egyenletes eloszlás a (0,1) intervallumon.
Definition uniform.cpp:9
Véletlenszám-generátor.