Generating random numbers in Java language is relatively simple because there are ready-made methods to use. In mathematics, the Java language provides a method called random. This method allows the system to generate random numbers.
Second, generate random numbers through random classes.
In the Java language, besides the random method, you can also generate random numbers through the random class. Programmers can create random number generators by instantiating a random object. Such as Random i=new Random (). Through this statement, a Random number generator is created using the random class. count
Third, generate random characters.
Random methods can be used to generate random characters. For example, a random lowercase character can be generated by code: (char) ('a'+math.random () * ('z'-'a'+1)). In fact, this is similar to generating random numbers between any two numbers. The above code can generate any character in a range. By properly trimming this code, you can also generate random characters between any two characters and random characters with any uppercase characters. Its conversion method is similar to the random number in any range mentioned above.
Let's understand the usage of random numbers:
Random numbers are needed in different statistical techniques, such as when extracting representative samples from the statistical population, or when assigning experimental animals to different experimental groups, or when Monte Carlo simulation is carried out.
Real random numbers are generated by physical phenomena, such as coin toss, dice, wheels, noise of using electronic components, nuclear fission and so on. This kind of random number generator is called physical random number generator, which has the disadvantage of high technical requirements.
It is often enough to use pseudo-random numbers in practical applications. These series are "seemingly" random numbers, but they are actually generated by fixed and repeatable calculation methods. Random numbers generated by computers or calculators have a long periodicity. They are not really random, because they can actually be calculated, but they have statistical characteristics similar to random numbers. This kind of generator is called a pseudo-random number generator.
In really critical applications, such as cryptography, people generally use real random numbers.
C language, C++, C#, Java, Matlab and other programming languages and software have corresponding random number generation functions, such as rand.