Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <iterator>
  3. #include <algorithm>
  4. #include <random>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. template <typename T>
  10. void rand_perm(T data[], int N)
  11. {
  12.     default_random_engine dre;
  13.     dre.seed(time(NULL));
  14.     for (int i = 0; i < N; i++)
  15.     {  
  16.         uniform_int_distribution<int> uid(i, N - 1);
  17.         swap(data[i], data[uid(dre)]);
  18.     }
  19. }
  20.  
  21. void uni(int n)
  22. {
  23.     default_random_engine dre;
  24.     dre.seed(time(NULL));
  25.     uniform_real_distribution<float> uid;
  26.     ofstream file;
  27.     file.open("uni.csv");
  28.     for (int i = 0; i < n; i++)
  29.     {
  30.         file << uid(dre) << "\n";
  31.     }
  32.     file.close();
  33. }
  34.  
  35. void bin(int n)
  36. {
  37.     default_random_engine dre;
  38.     dre.seed(time(NULL));
  39.     binomial_distribution<int> bd(1000, 0.5);
  40.     ofstream file;
  41.     file.open("bin.csv");
  42.     for (int i = 0; i < n; i++)
  43.     {
  44.         file << bd(dre) << "\n";
  45.     }
  46.     file.close();
  47. }
  48.  
  49. void norm(int n)
  50. {
  51.     default_random_engine dre;
  52.     dre.seed(time(NULL));
  53.     normal_distribution<double> nd;
  54.     ofstream file;
  55.     file.open("norm.csv");
  56.     for (int i = 0; i < n; i++)
  57.     {
  58.         file << nd(dre) << "\n";
  59.     }
  60.     file.close();
  61. }
  62.  
  63. int main()
  64. {
  65.     int tab[10];
  66.     for (int i = 0; i < 10; i++)
  67.     {
  68.         tab[i] = i;
  69.     }
  70.     rand_perm(tab, size(tab));
  71.     for (int i = 0; i < 10; i++)
  72.     {
  73.         cout << tab[i] << " ";
  74.     }
  75.     cout<<endl;
  76.     uni(1000);
  77.     bin(1000);
  78.     norm(1000);
  79. }
  80. /*
  81.  Wchodzisz na google colab wklejasz kod. Wchodzisz w lewy pasek -> Files -> wrzucasz pliki z cpp i wywolujesz make_plot(uni.csv itd).
  82. import pandas as pd
  83. import seaborn as sns
  84.  
  85. def make_plot(filename):
  86.     data = pd.read_csv(filename)
  87.     return sns.distplot(data, hist=True, kde=True,
  88.              bins=int(300), color = 'blue',
  89.              hist_kws={'edgecolor':'black'})
  90.  
  91. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement