3 ms·
A useful snippet from the article: "RNGCryptoServiceProvider is generally a safer choice when you need to generate random bytes. Creating an instance of this c
by garganzol 8y ago
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."
- eterm 8y agoBoth 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.