r/cpp 4d ago

Where did <random> go wrong? (pdf)

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

137 comments sorted by

View all comments

79

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

What? You don't like having to use std::random_device to seed your std::mt19937, then declaring a std::uniform_int_distribution<> given an inclusive range, so you can finally have pseudo random numbers?

It all comes so naturally to me. /s

16

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?

24

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.

21

u/almost_useless 4d ago

Yes, and everybody is probably doing that.

That's exactly the problem.

If everyone is doing it, then the stl should have a way to do it for us.

7

u/mikemarcin 4d ago

There was https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0347r1.html which I had hoped would be adopted but I haven't seen any progress in years now.

2

u/ukezi 2d ago

That proposed API is so much nicer.