Java Random class basics

Ideas:

The Random class is divided into three steps:
 1.
 Import the package java.util.Random
 2. Create
 Random r = new Random (); // The small registration can be left blank
 3. Use to
 obtain a random number, (int range:- 2147483648 ~ 2147483647)) int num = r.nextInt ();
 Get a random int 'number (parameters represent the range, left closed and right open interval), int num = r.nextint (3);
 the meaning actually represents is : [0,3) 0 ~ 2 

import java.util.Random
public class Test01Random {
 public static void main(String[] agrs) {
	 Random r=new Random();
	 int num=r.nextInt();
	 System.out.println("输入的随机数字是"+num);
 }
}

The result is

The random number entered is 2134098103 (generated randomly by the system)

 

Published 10 original articles · Likes0 · Visits 90

Guess you like

Origin blog.csdn.net/Q791425037/article/details/105632661