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