3 ms·
std::rand has global state. Specifying the algorithm doesn't fix that. And this lets you (easily) generate more than just integers in the range [0, INT_MAX]. s
by cornstalks 11y ago
std::rand has global state. Specifying the algorithm doesn't fix that.
And this lets you (easily) generate more than just integers in the range [0, INT_MAX]. std::rand doesn't have that level of convenience.
There are all sorts of inconveniences with std::rand, and it looks like this solves the vast majority of them.
- ori_b 11y ago> std::rand has global state. Specifying the algorithm doesn't fix that. Adding other functions also doesn't fix std:rand. People use std::rand. They will continue to use std::rand, unless it's removed. And even then they'll keep using it, because implementations will add it back in for compatibility. There's already a simple, half baked, crude random number generator. It's possible to fix it so that it provides at least acceptable randomness, and isn't complete junk. Doing this breaks nothing. Why add another similar function with similar API issues?
- cornstalks 11y agoWhat is this "similar function" with "similar API issues"? C++11's random utilities and O'Neill's randutils aren't similar to std::rand at all. They're totally different beasts from std::rand. Making std::rand a decent RNG would probably make the world a better place. I'm not disagreeing with that. But even if std::rand used a decent algorithm, it's still a suboptimal API.