A class system.random specifically used to generate random numbers is provided in .NET Framework, you must import system namespace when using this class. Of course, namespace system is automatically imported in each ASP.NET page, so we can use this class directly. Computers are not possible to generate complete random numbers, so-called random number generators are complex operations for pre-selected random seeds by a certain algorithm, using the resulting result to completely randomly randomly, this random number is The number of pseudo randhes is called. The pseudo-random number is selected from a limited number of numbers with the same probability. The selected number does not have a complete randomness, but from a practical point of view, its randomness is sufficient. The choice of pseudo-random number is from the random seed, so the selection of random seeds is very important to ensure that the number of pseudo randoms received each time is "random". If the random seed is the same, the random number generated by the same random number generator will be the same. Generally, we use the parameters related to the system time as a random seed, which is also a method of using the random number generator in .NET Framework defaults to the default. We can initialize a random number generator in two ways: the first method does not specify a random seed, the system automatically selects the current time as a random seed: random random = new random (); second method can specify an int type parameter as Random Seed: Random Random = New Random (10) After, we can use this Random class object to generate random numbers, this time you want to use the random.next () method. This method uses quite flexible, you can even specify the upper and lower limits of the generated random number. In addition to the random.next () method, the Random class also provides a random.nextdouble () method to generate a random double-precision floating point number between 0.0-1.0: Double Dresult; Dresult = random.nextdouble (); A method similar to the random.nextdouble () method is Random.Sample (), which is the only difference between the random.nextdouble () method lies in the access level, we can look at their original declaration: protected virtual double sample (); public Virtual double nextdouble ();
script>