I was wondering what the performance implications are of using std::time(0) to seed random number generators. I assume that it's a system call (if not please correct me), which generally isn't the best option regarding performance. Assuming std::time(0) is used many times throughout a program, will there be severe performance implications if any?
P.S. I'm more curious than anything, as currently there aren't any performance issues.
Reseeding the RNG should be a rather rare event, so I don't think you need to be concerned about performance. If you are reseeding frequently enough to cause a performance issue, you might want to rethink your approach -- you may be doing more harm than good.
My old probability/statistics professor would tell you that if you seed your random generator more than once, you're doing it wrong. It doesn't get better when seeded again and again. It get worse! If that was for cryptographic applications it would be a major weakness, and even if it's not, there's no reason to.
So in short, yes, it's a system call, but you should only seed once, so it's completely absorbed in the rest of the computations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With