简体   繁体   中英

Why is std::uniform_int_distribution<IntType>::operator() not const?

As I understand it, a distribution should not change when used to pull a random number. For a uniform distribution for example, its min/max should not change as we use it to generate random numbers, so why operator() is not const?

While min() and max() wont change, the distribution may contain state that helps it generate the next value. If operator() were const then this state could not be modified without having to guarantee that the object is thread safe. Providing that guarantee could be expensive and distributions are meant to be light weight.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM