News for hackers. Stuff that matters.
Re:Randomness in .NET by garganzol on Tuesday August 28, 2018 @06:27AM (#17857728)
A useful snippet from the article:

"RNGCryptoServiceProvider is generally a safer choice when you need to generate random bytes. Creating an instance of this class is expensive, so it’s better to populate a 400-byte array than call the constructor 100 times to populate a 4-byte array."

Re:Randomness in .NET by eterm on Tuesday August 28, 2018 @08:37AM (#17858294)
Both options there feel like the wrong solution.

Why would you call the constructor 100 times to popuate 100 4-byte arrays?

It's a service, surely the best approach to call the constructor once, then populate 100 4-byte arrays by calling GetBytes 100 times from the same service?

It is explicit code without the downside of the expensive constructor.

edit for clarification: It's true that getting all the data at once will still be much faster because it'll save all the other overhead, but it's not the constructor at fault there.