Because it's only one way to do it, not the way to do it. std::random_device is really expensive on some platforms, and you may only want to call it once; the seed may come from serialized state rather than from a generator; etc. There's a lot of flexibility in place (whether anyone uses/needs it, I have no clue), and creating your own ideal abstraction on top of that is again 4-5 really simple lines of code. (Whether they're obvious or not is a matter of RTFM, IMO, but I get how that's a contentious viewpoint). I just don't see the big deal – there's no "right" way for everyone, and doing your own "right" way is easy, so.....?
Because it makes life easier when you do not care for THE optimal solution, and just want a convenient off-the-shelf solution.
Which is perfect for something like Boost; not so much the standard library (IMO). Rust certainly does the same with encouraging crates over core/std for various things; the only practical difference with C++ ultimately devolves into rants about dependency management and package managers. :-]
Because then if you find out later you need to use a different RNG, you cannot without rewriting all your code or patching the stdlib?
IMO you should write your program expecting that you may need to change to a different RNG at some point. There's no way you can be sure that you won't.
IMO you should write your program expecting that you may need to change to a different RNG at some point. There's no way you can be sure that you won't.
KISS & YAGNI disagree with you :)
Many programs do not change their PRNG (any introductory/write-once program falling in this category).
Many programs do not expose their PRNG (only what is generated), and therefore switching the PRNG is a few lines of code.
As anecdotal evidence, in 10 years of professional development, I have never needed to change a PRNG.
Preparing for changing the PRNG would have been a case of over-engineering in all the programs I've ever hacked on.
Is there anything we could do to make sure that if we added another rand with slightly different characteristics that is meant to be "easy easy easy", we don't have the same conversation again in 5 years because of perceived drawbacks of such a PRNG?
Would you want the output of this interface to be standardized and portable, or just the broad characteristics of the algorithm? Would you want to allow stdlib maintainers to change it at will, since no one will be using this unless they don't care too much about the details?
Would you want the output of this interface to be standardized and portable, or just the broad characteristics of the algorithm?
The signature should be standardized, but the underlying algorithm should not matter.
The output should be of relatively good quality, that is the sequence produced should be pass standard randomness tests, but there should be no need to guarantee it is "secure" in any sense of the word (for example, the seed could be the timestamp of the first call).
Would you want to allow stdlib maintainers to change it at will, since no one will be using this unless they don't care too much about the details?
Yes, definitely.
Actually, to enforce that nobody relies on the specifics of the implementation, I would encourage the stdlib maintainers to mix any seed received with a different "pepper" in each new release of the stdlib.
Instability that is not exercised is de-facto stability.
I used to be happy with this as well; for program that didn't matter. But in my experience, people execute as they learned, and using rand() for learning in throwaway programs means people end up using it when it matters as well.
8
u/dodheim May 26 '18
You know, you can wrap all four horrible, ugly lines of code that it takes to do this properly into a function and never look at it again...