Vous êtes sur la page 1sur 2

4/5/2016 normal_distribution ­ C++ Reference

Search:    Go
Not logged in

Reference <random> normal_distribution register log in

C++ class template
Information std:: normal_distribution <random>
Tutorials
Reference template <class RealType = double> class normal_distribution;
Articles Normal distribution
Forum Random number distribution that produces floating­point values according to a normal distribution, which is described by
the following probability density function:
Reference
C library:
Containers:
Input/Output:
 
Multi­threading:
Other: This distribution produces random numbers around the distribution mean (μ) with a specific standard deviation (σ). 
<algorithm>
<bitset> The normal distribution is a common distribution used for many kind of processes, since it is the distribution that the
<chrono> aggregation of a large number of independent random variables approximates to, when all follow the same distribution
<codecvt> (no matter which distribution).
<complex>
<exception> The distribution parameters, mean (μ) and stddev (σ), are set on construction. 
<functional>
<initializer_list> To produce a random value following this distribution, call its member function operator(). 
<iterator>
<limits>
<locale> Template parameters
<memory>
RealType
<new> A floating­point type. Aliased as member type result_type. 
<numeric> By default, this is double.
<random>
<ratio>
<regex>
<stdexcept> Member types
<string> The following aliases are member types of normal_distribution: 
<system_error>
<tuple> member type definition notes
<typeindex> result_type The first template parameter (RealType) The type of the numbers generated (defaults to double)
<typeinfo>
param_type not specified The type returned by member param.
<type_traits>
<utility>
<valarray>
Member functions
<random> (constructor) Construct normal distribution (public member function)
distributions:
operator() Generate random number (public member function)
bernoulli_distribution
binomial_distribution reset Reset distribution (public member function)
cauchy_distribution param Distribution parameters (public member function)
chi_squared_distribution
min Minimum value (public member function )
discrete_distribution
exponential_distribution max Maximum value (public member function )
extreme_value_distribution
fisher_f_distribution Distribution parameters:
gamma_distribution
normal_distribution::mean Distribution mean (public member function)
geometric_distribution
lognormal_distribution normal_distribution::stddev Standard deviation (public member function)
negative_binomial_distribution
normal_distribution
piecewise_constant_distribution Non­member functions
piecewise_linear_distribution
operator<< Insert into output stream (function template )
poisson_distribution
student_t_distribution operator>> Extract from input stream (function template )
uniform_int_distribution relational operators Relational operators (function template )
uniform_real_distribution
weibull_distribution
generators:
Example
default_random_engine
discard_block_engine 1 // normal_distribution 
independent_bits_engine 2 #include <iostream>  Edit
3 #include <random> 
knuth_b
4
linear_congruential_engine
5 int main() 
mersenne_twister_engine 6 { 
minstd_rand 7   const int nrolls=10000;  // number of experiments 
minstd_rand0 8   const int nstars=100;    // maximum number of stars to distribute 
mt19937 9
mt19937_64 10   std::default_random_engine generator; 
11   std::normal_distribution<double> distribution(5.0,2.0); 
random_device
12
ranlux24
13   int p[10]={}; 
ranlux24_base 14
ranlux48

http://www.cplusplus.com/reference/random/normal_distribution/ 1/2
4/5/2016 normal_distribution ­ C++ Reference
ranlux48_base 15   for (int i=0; i<nrolls; ++i) { 
shuffle_order_engine 16     double number = distribution(generator); 
17     if ((number>=0.0)&&(number<10.0)) ++p[int(number)]; 
subtract_with_carry_engine
18   } 
other:
19
generate_canonical 20   std::cout << "normal_distribution (5.0,2.0):" << std::endl; 
seed_seq 21
22   for (int i=0; i<10; ++i) { 
normal_distribution 23     std::cout << i << "‐" << (i+1) << ": "; 
normal_distribution::(constructor) 24     std::cout << std::string(p[i]*nstars/nrolls,'*') << std::endl; 
member functions: 25   } 
normal_distribution::max 26
27   return 0; 
normal_distribution::mean
28 }
normal_distribution::min
normal_distribution::operator()
normal_distribution::param
Possible output: 
normal_distribution::reset
normal_distribution::stddev normal_distribution (5.0,2.0): 
0‐1: * 
non­member functions:
1‐2: **** 
operator<< 2‐3: ********* 
operator>> 3‐4: *************** 
relational operators 4‐5: ****************** 
5‐6: ******************* 
6‐7: *************** 
7‐8: ******** 
8‐9: **** 
9‐10: * 

See also
lognormal_distribution Lognormal distribution (class template )
chi_squared_distribution Chi­squared distribution (class template )
cauchy_distribution Cauchy distribution (class template )
fisher_f_distribution Fisher F­distribution (class template )
student_t_distribution Student T­Distribution (class template )

Home page | Privacy policy 
© cplusplus.com, 2000­2016 ­ All rights reserved ­ v3.1 
Spotted an error? contact us

http://www.cplusplus.com/reference/random/normal_distribution/ 2/2

Vous aimerez peut-être aussi