Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/numeric/random/lognormal distribution"

From cppreference.com
< cpp‎ | numeric‎ | random
m (r2.7.3) (Robot: Adding de, es, fr, it, ja, pt, ru, zh)
m (Shorten template names. Use {{lc}} where appropriate.)
Line 13: Line 13:
  
 
===Member types===
 
===Member types===
{{dcl list begin}}
+
{{begin}}
{{dcl list hitem | Member type | Definition}}
+
{{hitem | Member type | Definition}}
{{dcl list item | {{tt|result_type}} | {{c|RealType}}}}
+
{{| {{tt|result_type}} | {{c|RealType}}}}
{{dcl list item | {{tt|param_type}} | the type of the parameter set, unspecified}}
+
{{| {{tt|param_type}} | the type of the parameter set, unspecified}}
{{dcl list end}}
+
{{end}}
  
 
===Member functions===
 
===Member functions===
{{dcl list begin}}
+
{{begin}}
{{dcl list template | cpp/numeric/random/distribution/dcl list constructor | lognormal_distribution}}
+
{{| cpp/numeric/random/distribution/dcl list constructor | lognormal_distribution}}
{{dcl list template | cpp/numeric/random/distribution/dcl list reset | lognormal_distribution}}
+
{{| cpp/numeric/random/distribution/dcl list reset | lognormal_distribution}}
  
{{dcl list h2 | Generation}}
+
{{h2 | Generation}}
{{dcl list template | cpp/numeric/random/distribution/dcl list operator() | lognormal_distribution}}
+
{{| cpp/numeric/random/distribution/dcl list operator() | lognormal_distribution}}
  
{{dcl list h2 | Characteristics}}
+
{{h2 | Characteristics}}
{{dcl list template | cpp/numeric/random/lognormal_distribution/dcl list m}}
+
{{| cpp/numeric/random/lognormal_distribution/dcl list m}}
{{dcl list template | cpp/numeric/random/lognormal_distribution/dcl list s}}
+
{{| cpp/numeric/random/lognormal_distribution/dcl list s}}
{{dcl list template | cpp/numeric/random/distribution/dcl list param | lognormal_distribution}}
+
{{| cpp/numeric/random/distribution/dcl list param | lognormal_distribution}}
{{dcl list template | cpp/numeric/random/distribution/dcl list min | lognormal_distribution}}
+
{{| cpp/numeric/random/distribution/dcl list min | lognormal_distribution}}
{{dcl list template | cpp/numeric/random/distribution/dcl list max | lognormal_distribution}}
+
{{| cpp/numeric/random/distribution/dcl list max | lognormal_distribution}}
{{dcl list end}}
+
{{end}}
  
 
===Non-member functions===
 
===Non-member functions===
{{dcl list begin}}
+
{{begin}}
{{dcl list template | cpp/numeric/random/distribution/dcl list operator_cmp | lognormal_distribution }}
+
{{| cpp/numeric/random/distribution/dcl list operator_cmp | lognormal_distribution }}
{{dcl list template | cpp/numeric/random/distribution/dcl list operator_ltltgtgt | lognormal_distribution}}
+
{{| cpp/numeric/random/distribution/dcl list operator_ltltgtgt | lognormal_distribution}}
{{dcl list end}}
+
{{end}}
  
 
===Example===
 
===Example===

Revision as of 20:23, 31 May 2013

 
 
 
 
 
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) =
1
sx2 π
exp

-
(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

Template:cpp/numeric/random/distribution/dcl list constructorTemplate:cpp/numeric/random/distribution/dcl list resetTemplate:cpp/numeric/random/distribution/dcl list operator()Template:cpp/numeric/random/lognormal distribution/dcl list mTemplate:cpp/numeric/random/lognormal distribution/dcl list sTemplate:cpp/numeric/random/distribution/dcl list paramTemplate:cpp/numeric/random/distribution/dcl list minTemplate:cpp/numeric/random/distribution/dcl list max
Generation
Characteristics

Non-member functions

Template:cpp/numeric/random/distribution/dcl list operator cmpTemplate:cpp/numeric/random/distribution/dcl list operator ltltgtgt

Example

#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