Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/numeric/random/piecewise linear distribution"

From cppreference.com
< cpp‎ | numeric‎ | random
m (Text replace - "{{mark c++11 feature}}" to "{{mark since c++11}}")
(+example)
Line 39: Line 39:
 
{{example cpp
 
{{example cpp
 
  | code=
 
  | code=
 +
#include <iostream>
 +
#include <iomanip>
 +
#include <string>
 +
#include <map>
 +
#include <random>
 +
int main()
 +
{
 +
    std::random_device rd;
 +
    std::mt19937 gen(rd());
 +
    // increase the probability from 0 to 5
 +
    // remain flat from 5 to 10
 +
    // decrease from 10 to 15 at the same rate
 +
    std::vector<double> i{0, 5, 10, 15};
 +
    std::vector<double> w{0, 1,  1, 0};
 +
    std::piecewise_linear_distribution<> d(i.begin(), i.end(), w.begin());
 +
 +
    std::map<int, int> hist;
 +
    for(int n=0; n<10000; ++n)
 +
        ++hist[d(gen)];
 +
    for(auto p : hist)
 +
        std::cout << std::setw(2) << p.first << ' ' << std::string(p.second/100,
 +
}
 
  | output=
 
  | output=
 +
0 *
 +
1 ***
 +
2 ****
 +
3 ******
 +
4 *********
 +
5 *********
 +
6 *********
 +
7 **********
 +
8 *********
 +
9 **********
 +
10 *********
 +
11 *******
 +
12 ****
 +
13 ***
 +
14 *
 
}}
 
}}

Revision as of 10:32, 19 January 2012

Template:cpp/numeric/random/piecewise linear distribution/sidebar

Defined in header <random>
template< class RealType = double >
class piecewise_linear_distribution;
(since C++11)

Contents

Member types

Template:tdcl list begin Template:tdcl list hitem Template:tdcl list item Template:tdcl list item Template:tdcl list end

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

Template:example cpp