Created
June 17, 2014 16:23
-
-
Save alekseyl1992/2de3975f88b009b4e53d to your computer and use it in GitHub Desktop.
Normal distribution from uniform distribution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdio> | |
#include <cmath> | |
#include <ctime> | |
#include <vector> | |
#include <algorithm> | |
#include <array> | |
float getVal() { | |
float t2 = 0; | |
int n = 1000; | |
for (int i = 0; i < n; ++i) { | |
t2 += float(rand()) / float(RAND_MAX); | |
} | |
t2 /= n; | |
return (t2 - 0.5)*sqrt(12*n); | |
} | |
int main() | |
{ | |
srand(time(0)); | |
//generate seq | |
std::vector<float> seq; | |
for (int i = 0; i < 300; ++i) | |
seq.push_back(getVal()); | |
//analize | |
auto minmax = std::minmax_element(seq.begin(), seq.end()); | |
auto constexpr zonesCount = 10; | |
std::array<int, zonesCount> stat = {0}; | |
auto zoneSize = (*minmax.second - *minmax.first)/(zonesCount-1); | |
for (auto el: seq) | |
stat[(el - *(minmax.first))/zoneSize]++; | |
//output | |
for (auto el: stat) { | |
for (int i = 0; i < el; ++i) | |
std::cout << "o"; | |
std::cout << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment