Difference between revisions of "cpp/numeric/random/lognormal distribution"
From cppreference.com
m |
|||
Line 29: | Line 29: | ||
{{dcl list h2 | Characteristics}} | {{dcl list h2 | Characteristics}} | ||
{{dcl list template | cpp/numeric/random/lognormal_distribution/dcl list m}} | {{dcl list template | cpp/numeric/random/lognormal_distribution/dcl list m}} | ||
− | {{dcl list template | cpp/numeric/random/lognormal_distribution/dcl list | + | {{dcl list template | cpp/numeric/random/lognormal_distribution/dcl list }} |
{{dcl list template | cpp/numeric/random/distribution/dcl list param | lognormal_distribution}} | {{dcl list template | cpp/numeric/random/distribution/dcl list param | lognormal_distribution}} | ||
{{dcl list template | cpp/numeric/random/distribution/dcl list min | lognormal_distribution}} | {{dcl list template | cpp/numeric/random/distribution/dcl list min | lognormal_distribution}} |
Revision as of 02:53, 14 July 2012
Defined in header <random>
|
||
template< class RealType = double > class lognormal_distribution; |
(since C++11) | |
The lognormal_distribution random number distribution produces random numbers x > 0 according to a log-normal distribution:
- f(x; m,s) =
exp⎛1 sx√2 PI
⎜
⎝-
⎞(ln x - m)2 2s2
⎟
⎠
The parameter m is the mean and the parameter s the standard deviation.
Contents |
Member types
Member type | Definition |
result_type
|
RealType |
param_type
|
the type of the parameter set, unspecified |
Member functions
Non-member functions
Example
Run this code
#include <iostream> #include <iomanip> #include <string> #include <map> #include <random> #include <cmath> int main() { std::random_device rd; std::mt19937 gen(rd()); std::lognormal_distribution<> d(1.6, 0.25); std::map<int, int> hist; for(int n=0; n<10000; ++n) { ++hist[std::round(d(gen))]; } for(auto p : hist) { std::cout << std::fixed << std::setprecision(1) << std::setw(2) << p.first << ' ' << std::string(p.second/200, '*') << '\n'; } }
Output:
2 3 *** 4 ************* 5 *************** 6 ********* 7 **** 8 * 9 10 11 12
External links
- Weisstein, Eric W. "Log Normal Distribution." From MathWorld--A Wolfram Web Resource.
- Log-normal distribution. From Wikipedia.