Although it is possible to use the random class to generate stochastic numbers. But it is the system clock seed, so there is a large number of repeated pseudo-random numbers generated.
You can use a RNGCryptoServiceProvider() relative true random number generation.
Generated by the cryptographic service provider (CSP) random number generator (RNG)
Detailed implementations such as the following
byte[] randombytes = new Byte[4]; RNGCryptoServiceProvider Rngcrypto = new RNGCryptoServiceProvider (); Rngcrypto.getbytes (randombytes); int rngnum = Bitconverter.toint32 (randombytes, 0);//This is a random number
The result is that there are positive negative numbers (seemingly nine and above)
Suppose you want a 0-100-range random number
Rngnum = rngnum% 100;
Take more than you can.
Use the two namespaces that you want to add
Using System.Security.Cryptography;
Using System;
In addition, even though the random number of such methods produces more confusion. But the calculation will result in very large overhead and need attention.
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Unity3d C # Generates a true random number