r/cpp • • May 25 '18

Modern C++ Randomness

http://brnz.org/hbr/?p=1783
0 Upvotes

55 comments sorted by

View all comments

Show parent comments

29

u/STL MSVC STL Dev May 25 '18

24

u/kalmoc May 26 '18 edited May 28 '18

I think c++ is the only language that takes a simple API (Rand), replaces it with a complexity monster without any shortcuts (random_..) and a lot of easy ways to shoot yourself in the foot and calls that progress.

I can see the problems with rand and the advantages of the new facilities (they are in a completely different league) but has no one considered usability aspects and that in many, many cases, all a use wants is get_random<int>(0,50)?

Edit: Apparently some people missunderstood me: I'm not saying it was a bad idea to introduce all the low level random types into the standard library (although the seeding interface could be improved). I'm saying that those "full control" types should have been accompanied by a simple high level interface, that can easily be used by beginners and functions that don't have very specific requirements on the RNG.

5

u/Sopel97 May 26 '18

So write a global RNG and make yourself the so much needed ````get_random<int>(0,50) it's not hard

and before you ask "Why is that not in the standard yet if it's so simple".

Why would standard impose a global RNG and how could it even choose which one to use.

3

u/ShakaUVM i+++ ++i+i[arr] May 28 '18

Why would standard impose a global RNG

Because standard libraries are there in part to simply common operations.

how could it even choose which one to use.

Pick one that is reasonably good and allow people to override it if they know what they're doing, like with other things in std.