Pros and cons of RNGCryptoServiceProvider

后端 未结 4 910
一生所求
一生所求 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:19

    Yes, there is only one more. As Charlie Martin wrote System.Random is faster.

    I would like to add the following info:

    The RNGCryptoServiceProvider is the default implementation of a security standards compliant random number generator. If you need a random variable for security purposes, you must use this class, or an equivalent, but don't use System.Random because it is highly predictable.

    For all other uses the higher performance of System.Random, and equivalent classes, are welcome.

提交回复
热议问题