Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iterator>
- #include <algorithm>
- #include <random>
- #include <fstream>
- using namespace std;
- template <typename T>
- void rand_perm(T data[], int N)
- {
- default_random_engine dre;
- dre.seed(time(NULL));
- for (int i = 0; i < N; i++)
- {
- uniform_int_distribution<int> uid(i, N - 1);
- swap(data[i], data[uid(dre)]);
- }
- }
- void uni(int n)
- {
- default_random_engine dre;
- dre.seed(time(NULL));
- uniform_real_distribution<float> uid;
- ofstream file;
- file.open("uni.csv");
- for (int i = 0; i < n; i++)
- {
- file << uid(dre) << "\n";
- }
- file.close();
- }
- void bin(int n)
- {
- default_random_engine dre;
- dre.seed(time(NULL));
- binomial_distribution<int> bd(1000, 0.5);
- ofstream file;
- file.open("bin.csv");
- for (int i = 0; i < n; i++)
- {
- file << bd(dre) << "\n";
- }
- file.close();
- }
- void norm(int n)
- {
- default_random_engine dre;
- dre.seed(time(NULL));
- normal_distribution<double> nd;
- ofstream file;
- file.open("norm.csv");
- for (int i = 0; i < n; i++)
- {
- file << nd(dre) << "\n";
- }
- file.close();
- }
- int main()
- {
- int tab[10];
- for (int i = 0; i < 10; i++)
- {
- tab[i] = i;
- }
- rand_perm(tab, size(tab));
- for (int i = 0; i < 10; i++)
- {
- cout << tab[i] << " ";
- }
- cout<<endl;
- uni(1000);
- bin(1000);
- norm(1000);
- }
- /*
- Wchodzisz na google colab wklejasz kod. Wchodzisz w lewy pasek -> Files -> wrzucasz pliki z cpp i wywolujesz make_plot(uni.csv itd).
- import pandas as pd
- import seaborn as sns
- def make_plot(filename):
- data = pd.read_csv(filename)
- return sns.distplot(data, hist=True, kde=True,
- bins=int(300), color = 'blue',
- hist_kws={'edgecolor':'black'})
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement