Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | numeric‎ | random
m (Shorten template names. Use {{lc}} where appropriate.)
m (Update links.)
Line 21: Line 21:
 
===Member functions===
 
===Member functions===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/numeric/random/distribution/dcl list constructor | lognormal_distribution}}
+
{{dsc inc | cpp/numeric/random/distribution/constructor | lognormal_distribution}}
{{dsc inc | cpp/numeric/random/distribution/dcl list reset | lognormal_distribution}}
+
{{dsc inc | cpp/numeric/random/distribution/reset | lognormal_distribution}}
  
 
{{dsc h2 | Generation}}
 
{{dsc h2 | Generation}}
{{dsc inc | cpp/numeric/random/distribution/dcl list operator() | lognormal_distribution}}
+
{{dsc inc | cpp/numeric/random/distribution/operator() | lognormal_distribution}}
  
 
{{dsc h2 | Characteristics}}
 
{{dsc h2 | Characteristics}}
{{dsc inc | cpp/numeric/random/lognormal_distribution/dcl list m}}
+
{{dsc inc | cpp/numeric/random/lognormal_distribution/m}}
{{dsc inc | cpp/numeric/random/lognormal_distribution/dcl list s}}
+
{{dsc inc | cpp/numeric/random/lognormal_distribution/s}}
{{dsc inc | cpp/numeric/random/distribution/dcl list param | lognormal_distribution}}
+
{{dsc inc | cpp/numeric/random/distribution/param | lognormal_distribution}}
{{dsc inc | cpp/numeric/random/distribution/dcl list min | lognormal_distribution}}
+
{{dsc inc | cpp/numeric/random/distribution/min | lognormal_distribution}}
{{dsc inc | cpp/numeric/random/distribution/dcl list max | lognormal_distribution}}
+
{{dsc inc | cpp/numeric/random/distribution/max | lognormal_distribution}}
 
{{dsc end}}
 
{{dsc end}}
  
 
===Non-member functions===
 
===Non-member functions===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/numeric/random/distribution/dcl list operator_cmp | lognormal_distribution }}
+
{{dsc inc | cpp/numeric/random/distribution/operator_cmp | lognormal_distribution }}
{{dsc inc | cpp/numeric/random/distribution/dcl list operator_ltltgtgt | lognormal_distribution}}
+
{{dsc inc | cpp/numeric/random/distribution/operator_ltltgtgt | lognormal_distribution}}
 
{{dsc end}}
 
{{dsc end}}
  

Revision as of 23:20, 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/lognormal distribution/dsc mTemplate:cpp/numeric/random/lognormal distribution/dsc s
constructs new distribution
(public member function) [edit]
(C++11)
resets the internal state of the distribution
(public member function) [edit]
Generation
generates the next random number in the distribution
(public member function) [edit]
Characteristics
(C++11)
gets or sets the distribution parameter object
(public member function) [edit]
(C++11)
returns the minimum potentially generated value
(public member function) [edit]
(C++11)
returns the maximum potentially generated value
(public member function) [edit]

Non-member functions

(C++11)(C++11)(removed in C++20)
compares two distribution objects
(function) [edit]
performs stream input and output on pseudo-random number distribution
(function template) [edit]

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