Normal distribution functions in STL libraries

Source: Internet
Author: User

In the design of a lottery program, it is sometimes necessary to have a probability that "there is a greater likelihood of getting a common result, a smaller possibility of getting a bad or excellent result", which can be obtained by using a normal distribution function.

A series of randomly distributed functions have been provided in the STL, including normal distribution, Poisson distribution, etc.

Header file: Random

Function: std::normal_distribution<type> distribution (σ,μ)

where σ is the average mathematical expectation of the normal distribution, that is, the peak x value of the regular curve, the greater the μ value curve is about slow, the other is steeper, on the x-axis, (0,σ*μ) occupy most of the curve of the space, (-∞,0] and [σ*μ,+∞) can be considered a mathematical impossibility event.

    /*      with normal distribution, we can create the events like "have a great chance     to get medium result, and have a littl E chance to get bad or too good result "    *    /std::d efault_random_engine Generator;    Std::normal_distribution<double> distribution (5.0,2.0);     // STD Pesudo also needs seed to avoid generating fixed random value.    double number = distribution (generator);

It is important to note that the std::d Efault_random_engine also needs to use Srand (seed) to set a different seed before using it as before, otherwise the results will be the same each time.

Normal distribution functions in STL libraries

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.