In the process of generating random numbers, useful comparisons, such as artificial intelligence, and so on, here for the J2ME in the production of random number of operations to do a simple collation, I hope that we can help. Unlike J2ME and J2SE, you cannot use the random of the math class to generate random numbers, only using the random class of the Java.util package to generate random numbers.
First, create an object of type random
Random Random = new Random ();
Random Random = new Random (10010010);
Both of these are ways to create random objects, the first of which uses the default construction method, and is completely equivalent to the following code actions:
Random Random = new Random (System. Currenttimemillis ());
Rather, it is created using the current time as the seed number. The second way is to create a seed number by specifying it yourself. You can use either of these two methods as needed.
Second, generate random numbers
Once we have created random objects, we can generate random numbers:
Generate random integer: int k = Random.nextint ();
Generate random long integers: long L = Random.nextlong ();
Third, generate the specified range of numbers
For example, to generate a random number between 0-10:
int k = Random.nextint ();
Int J = Math.Abs (k% 10);
First, we generate a random integer k, then use K and 10 to get the remainder, and finally use the ABS method of the math class to take the absolute value and obtain the random number between 0-10. Get a random number between 0-15, like this:
int k = Random.nextint ();
Int J = Math.Abs (k% 15);
Get a random number between 10-20:
int k = Random.nextint ();
Int J = Math.Abs (k% 10) + 10;