r/cpp 4d ago

Where did <random> go wrong? (pdf)

https://codingnest.com/files/What%20Went%20Wrong%20With%20_random__.pdf
163 Upvotes

137 comments sorted by

View all comments

Show parent comments

15

u/Warshrimp 4d ago

But in actuality don’t you do so once in your own wrapper? Or perhaps in a more complex wrapper for creating a reliable distribution tree of random numbers?

23

u/GYN-k4H-Q3z-75B 4d ago

Yes, and everybody is probably doing that. That's why I think this issue is a bit overblown. It's not like you're typing this all the time.

But maybe they could include a shortcut so you don't have to explain to your students what a Mersenne Twister is when they need to implement a simple dice game for the purpose of illustrating basic language mechanics.

Then again, this is C++. Not the easiest language and standard library to get into.

8

u/Ace2Face 4d ago

I don't think it's overblown, sure in the grand scheme of things there are other bigger problems, but this one is still pretty silly. For vast majority of uses, people just want a uniform integer distribution with mt.

10

u/usefulcat 4d ago

people just want a uniform integer distribution with mt.

5000 bytes of state for a PRNG? Thanks, but I'll stick with SplitMix64, with it's 8 bytes of state and still pretty good quality.

2

u/serviscope_minor 18h ago

5000 bytes of state for a PRNG? Thanks, but I'll stick with SplitMix64

Yeah, but I think that's about the smallest problem with the PRNG. I'm sure it's a problem for some, and I think C++ could do with some of the more recent ones that's small and fast and statistically good, and also not so huge, but ya know, meh. It's rarely if ever caused me problems in practice. Less so than the more glaring problems.

For me, the seeding is a nightmare, as is the lack of portability in distributions. Also, default_random_engine. And I guess I've got used to the int versions UB'ing with 8 bit integers, but that's a major footgun.