C++11 weibull distribution random
The The C++11 weibull distribution ( or weibull_distribution) produces random numbers x ≥ 0 using the respective discrete probability function of the weibull_distribution-the function is shown at the end of the post.
Link :C++11 random number generator
The class declaration of the distribution is shown below.
template<class RealType = double> class weibull_distribution ;
The distribution produces only floating point values and the default type of the distribution is double type.
The class types and all the member functions is given below.
Types
typedef RealType result_type; typedef unspecified param_type;
The RealType is a type definition of the distribution type.And the param_type is a structure,however the definition will vary from compiler to compiler.
Constructors and reset function
explicit weibull_distribution(RealType a = 1.0, RealType b = 1.0); explicit weibull_distribution(const param_type& parm); void reset( ); [/coce] <p>The first constructor accept two parameters 'a' and 'b',they are used in calculating the probability of the random values in the distribution.The relation <b>0 < a</b> and <b>0 < b</b>.</p> <p>The second constructor accept a reference to param_type object.If this constructor is called the 'a' and 'b' values is assigned from the 'a' and 'b' values of the param_type object-param_type constructor also accept two parameters 'a' and 'b'.</p> weibull_distribution< > wd( 560 , 405); weibull_distribution<float >::param_type pt( 88 , 99 ); weibull_distribution<float > wd1( pt) ; //’a’ is 88 and b is ’99’ which are assigned from the ‘a’ and ‘b’ of the pt object weibull_distribution< > wd2( pt ) ; //error! , type of pt is float but type of wd2 is double type
Generating functions
template<class URNG> result_type operator( )(URNG& g); template<class URNG> result_type operator( )(URNG& g, const param_type& parm);
the first operator() function
The generated random sequence is obtained using the operator() function.The first overloaded operator() accept URNG(Uniform Random Number Generator) or engine.
weibull_distribution< > wd( 560 , 405); ranlux24_base r24 ; cout<< wd(r24) << ” ” << wd(r24) ;
Output in Code::blocks,
the second operator( ) function
The second overloaded operator( ) function accept URNG and param_type object.
weibull_distribution<float >::param_type pt( 88 , 99 ); weibull_distribution<float > wd ; default_random_engine dre ; cout<< wd(dre , pt) << ” ” << wd(dre , pt) ;
Output in Code::blocks,
Property functions
result_type a( ) const ; result_type b() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const;
a() function
The a() function returns the value of 'a' parameter.
weibull_distribution< > wd( 560 , 405); cout<< wd.a();
Output,
b() function
The b() function returns the value of 'b' parameter.
weibull_distribution< > wd( 560 , 405); cout<< wd.b();
Output,
param( )
This function returns the param_type object.
weibull_distribution<float >::param_type pt( 88 , 99 ); cout<< pt.a() << endl; //param_type has it’s own version of a() function weibull_distribution<float > wd(1000 , 200) ; pt=wd.param( ); cout<< wd.a( ) << endl ;
Output,
1000
param(param_type)
Using this function we can change the 'a' and 'b' value of the distribution to the 'a' and 'b' value of the param_type object by passing the param_type object.
weibull_distribution<long double > wd ; cout<< wd.param( ).b( ) << endl ; //same as wd.b( ) weibull_distribution<float >::param_type pt(34 , 90); wd.param( pt ); cout<< wd.param().b() << endl ;
Output,
90
min() function
The min() returns the smallest value the distribution can generate,which is the value 0.
weibull_distribution< > wd(900 , 10) ; cout<< wd.min( ) ;
Output,
max() function
The max() returns the smallest value the distribution can generate,which is the value 0.
weibull_distribution<long double > wd(900 , 10) ; cout<< wd.max( ) ;
Output,
Side note
weibull_distribution roduces random numbers x≥0 distributed according to the probability density function