简体   繁体   中英

Setting the min and max bounds for a random distribution class member, at run-time?

I have a C++ uniform distribution object. However, it is a class member, not on the stack (like every example seems to be).

I would like to set the upper and lower bounds of the distribution after reading config at run-time.

I saw there is a reset() member, but this doesn't allow passing a min and max.

What's the best way change the upper and lower bounds after construction? Should I just create one on the stack and assign it to my class member?

Just reassign it:

dist = std::uniform_int_distribution<int>(min, max);

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