Pros and cons of RNGCryptoServiceProvider

后端 未结 4 897
一生所求
一生所求 2020-12-01 09:02

What are the pros and cons of using System.Security.Cryptography.RNGCryptoServiceProvider vs System.Random. I know that RNGCryptoServiceProvi

4条回答
  •  借酒劲吻你
    2020-12-01 09:21

    A cryptographically strong RNG will be slower --- it takes more computation --- and will be spectrally white, but won't be as well suited to simulations or Monte Carlo methods, both because they do take more time, and because they may not be repeatable, which is nice for testing.

    In general, you want to use a cryptographic PRNG when you want a unique number like a UUID, or as a key for encryption, and a deterministic PRNG for speed and in simulation.

提交回复
热议问题