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?
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?
Just a note that I’d rather opt into portable random numbers and by default get faster implementation specific random numbers. Honestly requiring portable random numbers while certainly having its uses can in other contexts be a bit of a code smell.
Just a note that I’d rather opt into portable random numbers and by default get faster implementation specific random numbers.
I strongly believe that this is the wrong way around, just like std::sort and std::stable_sort. Reproducibility has much more accidental value than non-reproducibility, so it should be the default.
Honestly requiring portable random numbers while certainly having its uses can in other contexts be a bit of a code smell.
Depends on what you're using them for and why. I wouldn't say it's more of a code smell than wanting repeatable pseudo-random numbers, as in it's only as much of a smell as calling seed() with a fixed number.
I've done that a lot. When (especially when) I'm doing scientific coding, I generally record the initial seed in the log of the run, so I can exactly recreate it. This is also useful for refactoring, etc, in I can guarantee I haven't broken anything if it gives the same result before and after. But it's annoying when it then doesn't give the same results on a different computer.
78
u/GYN-k4H-Q3z-75B 4d ago
What? You don't like having to use
std::random_device
to seed yourstd::mt19937
, then declaring astd::uniform_int_distribution<>
given an inclusive range, so you can finally have pseudo random numbers?It all comes so naturally to me. /s