In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how C++ generates random numbers. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
C library pseudorandom number generator
Rand
Srand
Most of the time it takes time to generate the seed of the random generator
Int GetRandomNum (int min, int max,int seed)
{
/ / srand ((unsigned) time (NULL)); / / generate seed
Srand (seed)
Return (rand ()% (max-min) + min)
}
Pseudorandom number generator introduced by cymbal 11. Random numbers are abstracted into two parts: random number engine and distribution. The engine is used to generate random numbers, and the distribution produces random numbers with a specific distribution.
The commonly used one is linear uniform distribution.
Uniform_int_distribution
Uniform_real_distribution
Std::random_device rd;// to generate a random number as a seed
Std::uniform_int_distribution uni_dist (0, 9999999); / / Random number generators in a specified range
Std::cout (std::uniform_int_distribution
< unsigned int >(0, maxRand))
Rand0Engine = make_shared (rd ())
Ranlux48Engine = make_shared (rd ())
}
Std::random_device rd
Std::shared_ptr mtEngine;//32-bit Mersenne Twister by Matsumoto and Nishimura, 1998
Std::shared_ptr mtEngine64; / / 64-bit Mersenne Twister by Matsumoto and Nishimura, 2000 (Matset rotation algorithm)
Std::shared_ptr rand0Engine
Std::shared_ptr ranlux48Engine
Std::shared_ptr > dist
}
Int main ()
{
Cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.