Package Com.day10.Random class;
Import Java.util.Random;
public class Demorandom {
/**
* @param args
* Common Objects (Overview of the Random class and methods used)
* Overview of the A:random class
* This class is used to generate random numbers if you create two random instances with the same seed,
* The same method call sequence is made for each instance, and they will generate and return the same sequence of numbers.
* B: Construction method
* Public Random ()
* Public Random (long Seed)
* C: Member method
* public int Nextint ()
* public int Nextint (int n) (Key Mastery)
*/
public static void Main (string[] args) {
Random r=new random ();
int X=r.nextint ();
SYSTEM.OUT.PRINTLN (x);//The number randomly generated within the value range of int
Request to Master
System.out.println (R.nextint (100));//number of randomly generated [0,100]
Random r1=new Random (1000);
int A=r1.nextint ();
int B=r1.nextint ();
System.out.println (a);//-1244746321 this number every time, because it's the same seed.
System.out.println (b);//1060493871 This number every time, because it's the same seed.
}
}
Java-random class