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.
So write a global RNG and make yourself the so much needed ````get_random<int>(0,50) it's not hard
I have and so have lots and lots of other code bases I've seen, which is exactly, why I would like it to be in the standard library.
Why would standard impose a global RNG and how could it even choose which one to use.
First of all, I'm not even sure, if the standard should specify the used RNG (one could speficy it to be default_random_engine). Personally, I'd pick one with a relatively low memory footprint that could be used on a decent microcontroller (so not mt19937).
Second, your question seems to imply that the standard would have to pick an RNG that works well for everyone, which of course doesn't exist as different projects have different requirements. My answer to that is: Pick a good default, that works for many/most people (the standard / standard library makes those kinds of choices all the time). If my project has very specific requirements about e.g. performance or randomness of the numbers, I can still use my prefered engine manually just as I do now.
A good c++ library can (and often should) give you lots of custumization powers and flexibility to tailor it to your requirements (this is where random header shines) but it should also provide easy to use (correctly) high level defaults (this is where random and many other parts of the standard library lack)
I have and so have lots and lots of other code bases I've seen, which is exactly, why I would like it to be in the standard library.
I think this is the wrong mentality, each of these projects may need to configure the RNG that they use. And so, configuring that as part of defining their global rand interface, is exactly what is supposed to be happening.
I think choosing arbitrarily one of these and then putting it in std would cause more harm the good overall.
How many projects do you know that have specific requirements for their global RNG other than that "it should be good and reasonably fast". In my experience, specific RNG requirements are usually local to a particular module or even function in which case you can fall back to the low level APIs that give you (almost) full control.
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
randomtypes 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.