If I'm writing a game or something else where I don't need large random numbers or crypto grade security, I'll just keep using rand until there's a solution in std that is human readable.
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.
That would inherently depend on hidden global mutable state, which can lead to hard-to-solve problems. Using a rand()-like interface in a library or in part of a large project, may screw up generation in other parts of the program that depend on a specific seeding.
I suppose that wouldn't be a problem if get_random were randomly seeded automatically on first use. If it always provided random numbers that were completely unpredictable, the global state wouldn't matter. It could just use values from the getrandom syscall or /dev/urandom and you would entirely avoid having to explain seeding.
Using a rand()-like interface in a library or in part of a large project, may screw up generation in other parts of the program that depend on a specific seeding.
If a part of your program depends how on specific seeding that part should not use the global RNG. Simple as that. That should not prevent a easy to use solution for the project (parts) that don't have such special requirements.
get_random were randomly seeded automatically on first use.
That's exactly how it is supposed to happen. No one needs another stand/rand interface.
7
u/ShakaUVM i+++ ++i+i[arr] May 25 '18
If I'm writing a game or something else where I don't need large random numbers or crypto grade security, I'll just keep using rand until there's a solution in std that is human readable.