How do I generate a random int number?

前端 未结 30 2595
长发绾君心
长发绾君心 2020-11-21 11:02

How do I generate a random integer in C#?

30条回答
  •  独厮守ぢ
    2020-11-21 11:48

    The numbers generated by the inbuilt Random class (System.Random) generates pseudo random numbers.

    If you want true random numbers, the closest we can get is "secure Pseudo Random Generator" which can be generated by using the Cryptographic classes in C# such as RNGCryptoServiceProvider.

    Even so, if you still need true random numbers you will need to use an external source such as devices accounting for radioactive decay as a seed for an random number generator. Since, by definition, any number generated by purely algorithmic means cannot be truly random.

提交回复
热议问题