Two random number instances: Random Number instances
/*
import java.util.Random;
public class random_1{
public static void main(String[] args) {
Random r=new Random();
int a=r.nextInt();
System. out. print ("random number:" + );
}
}
*/
// The following programs have the same effect as the above programs
public class random_1{
public static void main(String[] args) {
int r=(int)(Math.random()*10);
System.out.print(r);
}
}
In java, how does Mathradom () return a random number between two fixed values, for example, 15-24? I remember it, but now I forget it.
Returns a random number of 15-24.
Math. random () * (24-15) + 15;
--------------------------------------
Returns m ~ Random Number of n
Math. random () * (n-m) + m
Which of the four random numbers (for example, 1234) generated by the java verification code is better than the two random numbers (for example, 5 + 2? People you know give the principle
Random random = new Random ();
For (int I = 0; I <10; I ++ ){
Random. nextInt (50) + random. nextInt (50); random integers between 0 and 50
}
I hope my answer will be helpful to you.