RNGCryptoServiceProvider - Random Number Review

后端 未结 7 830
旧时难觅i
旧时难觅i 2020-12-05 17:48

While looking for best attempts at generating truly random numbers, I stumbled upon this code example.

Looking for opinions on this snippet.

<
7条回答
  •  爱一瞬间的悲伤
    2020-12-05 18:18

    It really depends on the intended use or requirement of the random number being generated.

    The Random class is useful for practical randomization like randomizing the order images display in an image rotator or rolls of a die.
    If, on the other hand, you need random numbers requiring a greater amount of security, like to generate a password or payment confirmation key, then using a class such as RNGCryptoServiceProvider or creating your own implementation of the abstract class RandomNumberGenerator that implements a cryptographic algorithm are better alternatives.

提交回复
热议问题